2007-08-20

Right click on treeview

I've triggered a backflash and surprised. Either I do not understand something or it is indeed a banal blunder in Treeview from WinForms.

On right mouse click context menu appears but tree node has not become selected. I've found one more similar complaint

It seems to be generally accepted behavior - right click and the selection moved to a node under the mouse and the menu appeared. The most interesting thing is that in Visual Studio it works exactly so.

Well, dumb fix:
private void treeView_MouseClick(object sender, MouseEventArgs e)
{

if (e.Button == MouseButtons.Right)
{

TreeNode node = treeView.GetNodeAt(e.X, e.Y);

if (node != null)
{
treeView.SelectedNode = node;

}
}
}


Update: 24.08.2007 And it is much better to tie the bug fix to NodeMouseClick

No comments:

Post a Comment