PDA

View Full Version : Select/De-select items in list box



av8tordude
06-03-2009, 04:45 PM
Can someone assist me in writing a simple code that will do this….

When I select (tick) “ALL APPCHS” in the list box, I would like all other items in the list box to be deselected (un-ticked). But, if “ALL APPCHS” is selected (ticked) and I select (tick) any other items in the listbox, I would like the “ALL APPCHS” to be deselected (un-ticked). I've attached an image to help in understand my request. Thank you in advance.

slamet Harto
06-03-2009, 11:54 PM
Hi

I have not download your attachement as the size is too big for my quota.
Please find the attached for reference.. but I forget the link or the Author on this.

Hope its helps.
Rgds, Harto

av8tordude
06-04-2009, 12:43 AM
I'm having difficulty writing this code. Here's what I have, but it gives an error stating "Could not get selected property. Type mismatch"



Dim lItem As Long

For lItem = 0 To APPCH.ListCount - 1
If APPCH.Selected("ALL APPCHS") = True Then
APPCH.Selected(lItem) = False
End If
Next

p45cal
06-04-2009, 02:14 AM
it won't like this:
If APPCH.Selected("ALL APPCHS") = True Then
because I think it only wants to see a number instead of "ALL APPCHS".

The following assumes the All Approaches item is the first one (listindex=0):
Private DisableEvents As Boolean
Private Sub APPCH_Change()
If Not DisableEvents Then
DisableEvents = True
With APPCH
If .Tag = "Y" Then
For i = 1 To .ListCount - 1
If Not .Selected(i) Then
.Selected(0) = False
Exit For
End If
Next i
Else
If Not (.Tag = "Y") Then
If .Selected(0) Then
For i = 1 To .ListCount - 1
.Selected(i) = False
Next i
End If
End If
End If
If .Selected(0) Then .Tag = "Y" Else .Tag = ""
End With
DisableEvents = False
End If
End Sub
One thing I'd do is when they've finished and click one of the buttons is have the code check whether they might have selected all approaches by ticking all of them (and not the All Approaches item). I wouldn't try select All Approaches and deselect all the others for them while they're selecting items, as they might be in the process of changing which items are selected and only intend to have all of them selected briefly.