Home All Groups Group Topic Archive Search About
Author
12 Mar 2006 7:42 AM
Martin
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

Author
12 Mar 2006 10:22 AM
Herfried K. Wagner [MVP]
"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/>
Author
12 Mar 2006 11:24 AM
Martin
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/>