Yet Another Newbie Listbox Question

  • Thread starter Thread starter Glen
  • Start date Start date
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
 
Add a MouseDown event handler and check which item you
clicked on, then select it in code (SelectedItem or SelectedIndex
property)

/claes
 
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
 
Back
Top