There may be a roundabout way to “disable” the checkbox within the ListBox. When you identify which item in the ListBox needs to be disabled, set the ItemData property for that item to a specific value:
' Disable a specific ListBox item.
Dim intIdx As Integer
For intIdx = 0 To lstDisable.ListCount - 1
If lstDisable.List(intIdx) = "Blue" Then
lstDisable.ItemData(intIdx) = 1
End If
Next intIdx
Next, you can check for the disabled item in the ListBox ItemCheck event and don’t allow the client to select that item:
Private Sub lstDisable_ItemCheck(Item As Integer)
' Check for disabled item and don't allow client
' to select it.
If lstDisable.ItemData(Item) = 1 Then
lstDisable.Selected(Item) = False
Exit Sub
End If
' Normal select process here, if necessary.
End Sub
What happens with the above code is, the client selects the item by clicking on the checkbox inside the ListBox. However, nothing happens, i.e. it remains unchecked.
If you need to make a disabled item “enabled” again, reset the ItemData property:
' Enable a disabled ListBox item.
Dim intIdx As Integer
For intIdx = 0 To lstDisable.ListCount - 1
If lstDisable.ItemData(intIdx) = 1 Then
lstDisable.ItemData(intIdx) = 0
End If
Next intIdx
This isn’t the cleanest way, especially for the client because they may call and ask why they can’t select a particular item.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.