[RESOLVED] Auto Select Item In ListBox
A Form has a ListBox wherein only 1 item is visible at a time. Usually when a ListBox is scrolled using the mouse, the previous/next item becomes visible to him but the item that becomes visible DOESN'T get selected. The user has to click the item explicitly to select it (of course, if a user uses the keyboard to scroll the ListBox, the items get selected too but that's a different matter).
What I want is when a user scrolls the ListBox using his mouse, the item that becomes visible to him should automatically get selected as well.
Can this be accomplished? If yes, how?
Note that the ListBox doesn't include CheckBoxes.
Re: Auto Select Item In ListBox
Code:
Private Sub List1_Scroll()
Dim i As Long
For i = 0 To List1.ListCount - 1
List1.Selected(i) = True
Next
End Sub
Something like that possibly but when is the item added exactly? because once you have scrolled to the bottom you cant go any further.
Re: Auto Select Item In ListBox
I tried your code mate but selecting any item in the ListBox directly selects the last item in the ListBox. Actuually I must confess that I framed my question a bit wrongly. I should have stated it clearly that when scrolling, I want to retrieve the item to which the user has scrolled to & not necessarily select that item & this code does that:
Code:
Private Sub List1_Scroll()
MsgBox List1.List(List1.TopIndex)
End Sub
If the ListBox has 5 items, say Item1.....Item5, then scrolling down with the mouse, if Item2 becomes visible in the ListBox, the message box says Item2. If the user scrolls to Item3 making it visible, then the message box displays Item3 so on & so forth. This is exactly what I wanted.
Once again sorry for the oversight.
Re: Auto Select Item In ListBox
So, is this resolved for you?
Re: Auto Select Item In ListBox
yes....yes....sorry....forgot to mark it [RESOLVED]....will do it now....better late than never, what say? ;-)