TreeView - Right-click on node doesn't select the node

0
0

It looks like in VWG. right-clicking a node would first select the node then display the context menu while under WiseJ, the node under the mouse is not selected before the context menu is displayed.  What’s the appropriate way to get the other behavior – select the node under the mouse (if any) before the context menu is displayed?

 

 

  • You must to post comments
0
0

Hi Carl,

Sorry for the late reply,
I wanted to inform you that the issue was fixed.

Best,
Alaa

//

  • You must to post comments
0
0

We also have the RightClickSelection property:

https://docs.wisej.com/api/wisej.web/lists-and-grids/treeview#rightclickselection

https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview#rightclickselection

https://docs.wisej.com/api/wisej.web/lists-and-grids/wisej.web.listbox#rightclickselection

Does’t work with a TreeNode with a ContextMenu, which is a bug just logged. You can also assign a ContextMenu to the TreeView instead each single node instead.

  • Carl Daniel
    That looks perfect. I’ll revert my solution once that bug is fixed.
  • You must to post comments
0
0

Here’s what I did, based on Kevin’s answer above.

public static void SelectOnRightClick(this TreeView tv)
{
// this needs to be "definitely assigned" due to the self-reference in the definition.
CollectionChangeEventHandler cceh = null;
cceh = (_, ccea) =>
{
if (ccea.Action == CollectionChangeAction.Add)
{
if (ccea.Element is TreeNode nd)
{
nd.ContextMenu = tv.ContextMenu;
nd.NodeMouseClick += (__, mce) => tv.SelectedNode = nd;
nd.Nodes.CollectionChanged += cceh;
}
}
};
tv.Nodes.CollectionChanged += cceh;
}

 

 

  • You must to post comments
0
0

Hi Carl,
Yes, you are right,
You can use this trick to get the result you wanted:

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
for (int i = 0; i < treeView1.Nodes.Count; i++)
{// Add event and load ContextMenu
treeView1.Nodes[i].ContextMenu = this.contextMenu1;
treeView1.Nodes[i].NodeMouseClick += Window1_NodeMouseClick;
}
}
private void Window1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{ //Select node
treeView1.SelectedNode = e.Node;
}

Happy coding,

Kevin (ITG)

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.