list box - Who's on First? (the user's mouse-click?)

wware

Registered User.
Local time
Today, 14:48
Joined
Feb 26, 2007
Messages
19
list box - 1st item alone OR mult items (not including the 1st)

If user selects 1st item in list box, I want to deselect all others. But, if the user selects the 2nd, 3rd, or 4th item I want to deselect 1st item only.

In other words, valid choices are:
1) 1st item only ("all")
2) one or more of the 2nd, 3rd, or 4th items

I think my main question is how to figure out which item the user just selected.

Did s/he just pick the 1st, so I should deselect the others?
Did s/he just pick the 2nd, so I should deselect the 1st?

Any help appreciated.
 
Never mind. I got it. Listindex property. Rookie question, I know.
--------------------------------------
Private Sub ListLineOfBusiness_Click()

If Me.Listlineofbusiness.ListIndex = 0 And Me!Listlineofbusiness.Selected(0) = True Then
Me!Listlineofbusiness.Selected(1) = False
Me!Listlineofbusiness.Selected(2) = False
Me!Listlineofbusiness.Selected(3) = False
End If

If Me.Listlineofbusiness.ListIndex = 1 And Me!Listlineofbusiness.Selected(1) = True Then
Me!Listlineofbusiness.Selected(0) = False
End If

If Me.Listlineofbusiness.ListIndex = 2 And Me!Listlineofbusiness.Selected(2) = True Then
Me!Listlineofbusiness.Selected(0) = False
End If

If Me.Listlineofbusiness.ListIndex = 3 And Me!Listlineofbusiness.Selected(3) = True Then
Me!Listlineofbusiness.Selected(0) = False
End If

End Sub
 
Better code for a long list.
-------------------------
Private Sub ListLineOfBusiness_Click()
Dim i As Integer

'if user selects "all" deselect all others
If Me.Listlineofbusiness.ListIndex = 0 And Me!Listlineofbusiness.Selected(0) = True Then
For i = 1 To Me.Listlineofbusiness.ListCount - 1
Me!Listlineofbusiness.Selected(i) = False
Next i
End If

'if user selects a specific item, deselect "all"
If Me.Listlineofbusiness.ListIndex <> 0 And Me!Listlineofbusiness.Selected(Me.Listlineofbusiness.ListIndex) = True Then
Me!Listlineofbusiness.Selected(0) = False
End If

End Sub
 
Better code for a long list.
-------------------------
Private Sub ListLineOfBusiness_Click()
Dim i As Integer

'if user selects "all" deselect all others
If Me.Listlineofbusiness.ListIndex = 0 And Me!Listlineofbusiness.Selected(0) = True Then
For i = 1 To Me.Listlineofbusiness.ListCount - 1
Me!Listlineofbusiness.Selected(i) = False
Next i
End If

'if user selects a specific item, deselect "all"
If Me.Listlineofbusiness.ListIndex <> 0 And Me!Listlineofbusiness.Selected(Me.Listlineofbusiness.ListIndex) = True Then
Me!Listlineofbusiness.Selected(0) = False
End If

End Sub

That's pretty slick code. I have a use for that in something I'm working on. :)
 
Glad you like it. I guess that means I officially wasn't talking to myself which appeared to be the case on this thread. It was a long day. Wendy
 
Glad you like it. I guess that means I officially wasn't talking to myself which appeared to be the case on this thread. It was a long day. Wendy

Just goes to show that you never know who might be reading a thread. :)Again, thanks for the code.
 

Users who are viewing this thread

Back
Top Bottom