|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Hittest on listbox?Hi all,
I'm trying to correct the (imho) wrong behaviour of a listbox when the user right-clicks on an item. I would like the selection to change when this happens, just like when the user uses the left mouse button. Most multi-item controls seem to have the hittest method, but in the documentation of the listbox I can't find it. Does anyone know how to do this? Tia, Martin "Martin" <x@y.com> schrieb: \\\> I'm trying to correct the (imho) wrong behaviour of a listbox when the > user right-clicks on an item. I would like the selection to change when > this happens, just like when the user uses the left mouse button. > Most multi-item controls seem to have the hittest method, but in the > documentation of the listbox I can't find it. Private Sub ListBox1_MouseUp( _ ByVal sender As Object, _ ByVal e As MouseEventArgs _: ) Handles ListBox1.MouseUp If e.Button = MouseButtons.Right Then Dim n As Integer = Me.ListBox1.IndexFromPoint(e.X, e.Y) If n <> ListBox.NoMatches Then Me.ListBox1.SelectedIndex = n ' Show context menu here using 'ContextMenu.Show'... End If End If End Sub /// -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> Brilliant! Thanks a lot.
Martin Show quoteHide quote "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message news:uu3XCAcRGHA.1608@TK2MSFTNGP09.phx.gbl... > "Martin" <x@y.com> schrieb: >> I'm trying to correct the (imho) wrong behaviour of a listbox when the >> user right-clicks on an item. I would like the selection to change when >> this happens, just like when the user uses the left mouse button. >> Most multi-item controls seem to have the hittest method, but in the >> documentation of the listbox I can't find it. > > \\\ > Private Sub ListBox1_MouseUp( _ > ByVal sender As Object, _ > ByVal e As MouseEventArgs _: > ) Handles ListBox1.MouseUp > If e.Button = MouseButtons.Right Then > Dim n As Integer = Me.ListBox1.IndexFromPoint(e.X, e.Y) > If n <> ListBox.NoMatches Then > Me.ListBox1.SelectedIndex = n > > ' Show context menu here using 'ContextMenu.Show'... > End If > End If > End Sub > /// > > -- > M S Herfried K. Wagner > M V P <URL:http://dotnet.mvps.org/> > V B <URL:http://classicvb.org/petition/>
Need some help with vb StatusStrip Control
How to abort a WinForms apps with no main window [VB.NET] How to store/load XML schema internally... Fields in Access database returned in alphabetical order datagridview combo box ASP.NET, CSS, and Netscape 7.1 Coding a TimeSpan latency when loading forms Best way to implement 2 controls on one window Best value Help file builder |
|||||||||||||||||||||||