Use right-click to select a listbox item

G

Guest

I have a context menu tied to a list box. When I right-click on an item, I'd like that item to be selected before the context menu invokes, similar to how Outlook Express works when right-clicking on mail items. I've figured out how to trap the right-click in the _MouseDown event, but can't figure out how to set the listbox's selected item to the item under the mouse pointer

Thanks

Billy
 
G

Guest

Found it with a little more digging in the docs..

Private Sub lbNames_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lbNames.MouseDow
If e.Button = MouseButtons.Right The
Dim pt As Poin
pt.X = e.
pt.Y = e.
lbNames.SelectedIndex = lbNames.IndexFromPoint(pt
End I
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top