Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

displaying a listbox item as checked or unchecked

Status
Not open for further replies.

daughtery

Programmer
Dec 12, 2006
66
US
In the code below I want to display the checkbox as checked or unchecked depending on a value in the recordset. I haven't been able to find how to do this. I've tried
"lstRtnMthProfile.Selected (1)" to check them but that throws an error.


Code:
 Do While Not rsMethodProfiles.EOF
        lstRtnMthProfile.Font = "Times New Roman"
        lstRtnMthProfile.FontBold = True
        lstRtnMthProfile.FontSize = 12
        lstRtnMthProfile.AddItem rsMethodProfiles.Fields("MethodDesc")
        If (IsNull(rsMethodProfiles("ruleID"))) Then
           lstRtnMthProfile.Selected (0) [red]'uncheck the box [/red]
        Else
           lstRtnMthProfile.Selected (1) [red]'Check the box[/red]
        End If
        rsMethodProfiles.MoveNext
   Loop
 

Did you try:
Code:
Dim i As Integer

With lstRtnMthProfile
    .Font = "Times New Roman"
    .FontBold = True
    .FontSize = 12

    Do While Not rsMethodProfiles.EOF
        .AddItem rsMethodProfiles!MethodDesc
        If (IsNull(rsMethodProfiles!ruleID)) Then
           .Selected(i) = False 'uncheck the box 
        Else
           .Selected(i) = True 'Check the box
        End If
        i = i +1
        rsMethodProfiles.MoveNext
   Loop
End With


Have fun.

---- Andy
 
Works great. But I have another question. How can I disable the ability for the user to check and uncheck the checkbox while still allowing them to select list items?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top