tree view

S

Stephen Haunts

Ok, I've got a tree view in my app, and when I click a new leaf with the
left mouse button I handle the AfterSelect event and change the context menu
for the tree view. But if I select the tree leaf with the right mouse
button it doesn't fire that event. How can I get it to fire the AfterSelect
event from the right mouse button.

Regards

Steve
 
M

Marc Scheuner [MVP ADSI]

Ok, I've got a tree view in my app, and when I click a new leaf with the
left mouse button I handle the AfterSelect event and change the context menu
for the tree view. But if I select the tree leaf with the right mouse
button it doesn't fire that event. How can I get it to fire the AfterSelect
event from the right mouse button.

I use this code snippet on the "MouseDown" event:

protected override void OnMouseDown(MouseEventArgs e)
{
base.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;
}
}
}

HTH
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