I am very new to .NET and I had to write a program in which there is a TreeView with different kind of nodes, Each kind of node has a different ContextMenuStrip, So I create multiple kind of ContextMenuStrip and assign then to different kind of TreeNode. Now my question is, when user show a context menu how should I find which TreeNode was the node that cause ContextMenuStrip to show. I try to use ContextMenuStrip.SourceControl but it return a TreeView and it never help me, because I know that my source is TreeView I want to know which node of the view! Now should I use some kind of hit test? and if yes what about ContextMenu that shown using keyboard?
I am very new to .NET and I had to write a program in
Share
You may use Tag property to “link” the source nodes.
For example, in your form’s Load event handler:
Then you can bind all ContextMenuStrip controls’ Opened event handlers to one method, as below:
There might be better ways to do it, but I think this should be able to solve your problem.
Updated 2012-10-17: