Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting from listbox with right mouse button 1

Status
Not open for further replies.

kyledunn

Programmer
Jan 2, 2001
145
US
If you left click on a line item in a listbox it selects the item. Clicking the right mouse button is detectable in the listbox but does not select the item. Is there a way to override this listbox behaviour and select an item with the right mouse button?

Kyle
 
In your right-button event handler, set the SelectedIndex property for the control.

Chip H.
Error on line 9: Object of type SIGNATURE expected
 
Hi Chip,

I was having a problem determining which item was being selected when the right mouse button was clicked in the listbox control but solved that by adding the listbox.TopIndex with the Y mouse position divided by the selected item's height. This gave me the item that was clicked by the right mouse button so I could assign the SelectedIndex. Thanks for your input.

Kyle
 
That was pretty clever! Any problems when the list has scrolled down some?

Chip H.
Error on line 9: Object of type SIGNATURE expected
 
It's working great even when scrolled down. The listbox.TopIndex property gives the correct index of the first visible item in the list even after scrolling. Knowing that I could correctly deduce from the mouse position which item was being selected. I now have right click delete capability in my custom control combo box. I'm happy.

Kyle
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top