I have TreeView with different level TreeNodes
I added same ContextMenuStrip to all parent TreeNodes and i want to get possibility to delete all child TreeNodes by opening that ContextMenuStrip and pressing “Delete all”
private void btn_delete_all_objects_Click(object sender, EventArgs e)
{
ToolStripMenuItem tsmi = (ToolStripMenuItem)sender; //that way i receive button "Delete all"
ContextMenuStrip cms = (ContextMenuStrip)tsmi.Owner; //this is ContextMenuStrip where this button...
TreeView tw = (TreeView)cms.SourceControl; //i can get TreeView :( BUT I NEED TreeNode!
TreeNode tn = tw.SelectedNode; //bah... if i select some of child nodes, then right click to open menu on parent, selected node is still that child
}
And i don’t know how to get that TreeNode where user clicked to open menu
Any ideas?
you can use
HitTest()method from tree view to find the node, like this,or you can focus the node on which the mouse clicked and use
treeView1.SelectedNodeproperty to manipulate in your menu items. By this way you can avoid using HitTest() on every context menu item…