Yet Another Newbie Listbox Question

G

Glen

Is there a way to make the right mouse button actually select an item in
a listbox as well as popup the associated context menu?

Thanks,
Glen Wolinsky
 
C

Claes Bergefall

Add a MouseDown event handler and check which item you
clicked on, then select it in code (SelectedItem or SelectedIndex
property)

/claes
 
M

Marc Scheuner [MVP ADSI]

Is there a way to make the right mouse button actually select an item in
a listbox as well as popup the associated context menu?

This is what I use for doing exactly that on my TreeView - I'm sure
you can adapt it for use in the Listbox!


protected override void OnMouseDown(MouseEventArgs e)
{
ase.OnMouseDown(e);

if (e.Button == MouseButtons.Right)
{
Point pt = new Point(e.X, e.Y);
this.PointToClient(pt);

TreeNode oCurrNode = this.GetNodeAt(pt);
if (oCurrNode == null)
return;

if (oCurrNode.Bounds.Contains(pt))
{
this.SelectedNode = oCurrNode;
}
}
}

Marc
================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 

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