c# - How can i fix the issue for context menu for Treeview click -


my code opening context menu on right-click treeview follows

private void contextmenu_opening(object sender, canceleventargs e)     {         if (convert.toint16(tvwach.selectednode.tag) == 1)         {             contextmenu.items.add(new);             contextmenu.items.remove(remove);             contextmenu.items.remove(saveas);             contextmenu.items.remove(save);             contextmenu.items.remove(addentry);         }         if (convert.toint16(tvwach.selectednode.tag) == 2)         {             contextmenu.items.add(new);             contextmenu.items.remove(remove);             contextmenu.items.remove(saveas);             contextmenu.items.remove(save);             contextmenu.items.remove(addentry);             new.text = "add fileheader";         }         if (convert.toint16(tvwach.selectednode.tag) == 3)         {             contextmenu.items.remove(new);             contextmenu.items.add(save);             contextmenu.items.add(saveas);             contextmenu.items.remove(remove); //added later             contextmenu.items.remove(addentry);         }         if (tvwach.selectednode.parent != null)         {             string str = tvwach.selectednode.parent.tostring().substring(10);             if (str == "batchheader")             {                 contextmenu.items.remove(new);                 contextmenu.items.remove(save);                 contextmenu.items.remove(remove);                 contextmenu.items.remove(saveas);                 contextmenu.items.add(addentry);             }         } 

and mouse down treeview follows

 private void tvwach_mousedown(object sender, mouseeventargs e)     {         if (e.button == mousebuttons.right)         {             contextmenu.show(tvwach, e.location);         }         location = e.location;     } 

but getting opened every on tree-view control need opened when click on nodes of tree-view.

any please

if want context menu displayed when user right-clicks on node, need include logic in mousedown event hander verify click event occurred on node.

you can determine node located @ particular point using hittest method provided treeview. example, modify current mousedown event handler include following code:

private void tvwach_mousedown(object sender, mouseeventargs e) {     if (e.button == mousebuttons.right)     {         if (tvwach.hittest(e.location).node != null)         {             contextmenu.show(tvwach, e.location);         }     } } 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -