Go to home page mail me! RSS Feed

Selecting a node on right click

Sunday, August 10, 2008 12:25 PM

There are so many things that I see or have seen in my development career that are unexplainable. Its leaves me with a grunt face, going, why in the world did Microsoft do this? Anyway, I've been doing a lot of windows client development these days and I noticed that when using a tree view control with a context menu, the actual tree view node does not get selected when you right click, it keeps the last selected node. Here is a fix for that.

   1:  private void treeView_MouseDown(object sender, MouseEventArgs e)
   2:  {
   3:      if (e.Button != MouseButtons.Right)
   4:          return;
   5:      treeView.SelectedNode = treeView.GetNodeAt(e.X, e.Y);
   6:  }

Your Comments.

No comments posted yet.

Your Reply.

Comment Form.

Fields denoted with a "*" are required.

You may also like to leave your email or website.

 
Please add 5 and 7 and type the answer here:

Preview Your Comment.

 
Next entries »