Hittest on listbox?

  • Thread starter Thread starter Martin
  • Start date Start date
M

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
 
Martin said:
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
///
 
Brilliant! Thanks a lot.

Martin

Herfried K. Wagner said:
\\\
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
///
 
Back
Top