Re: ListBox: How to only fire SelectedIndexChanged if the an item is directly selected. by Scott
Scott
Fri Jan 21 08:22:16 CST 2005
You can't overload the event, but you can write some code in the event to
manage this. If you use the ListBox.IndexFromPoint() method, you can
determine if there is an actual ListBox item under the cursor when it's
selected. The method returns "ListBox.NoMatches" if the mouse isn't over an
item in your list, so you can just put some conditional logic in your
SelectedIndexChanged event (looks something like this):
Dim pt as Point = <form>.PointToClient(Cursor.Position)
If <listbox>.IndexFromPoint(pt) <> ListBox.NoMatches Then
'do your processing
End If
Where you would replace <form> with the name of the containing form, and
<listbox> with the name of your ListBox.
HTH
- Scott
"felix" <felix666007_no_solicitation@yahoo.com> wrote in message
news:1106269329.153476.296800@z14g2000cwz.googlegroups.com...
> I would like to only fire SelectedIndexChanged if the an item is
> directly selected.
>
> example:
> I have a listbox with a few items in it. These items only half fill the
> listbox. If I click in the listbox, but not directly on an item (that
> is in the bottom half of the listbox), the bottom item is selected.
> Any ideas?
>
> Thanks!
>
> Felix
>