views:

90

answers:

1

Hi,

I am adding a right click functionality on individual nodes of a treeView in my C# code. The options like "Add", "Delete", "Rename" should pop up when the user right clicks in those nodes on the tree. Now depending on the node that is being clicked, I am filling up the menu as using the following statememnts:

contextMenuStrip1.Items.Add("Add");

Then if a different nodes is right clicked I use the following:

contextMenuStrip1.Items.Add("Rename");

There are some nodes where both the items have to be shown: contextMenuStrip1.Items.Add("Add"); contextMenuStrip1.Items.Add("Delete");

How do I write seperate event handlers for Add and Delete when both of them exist in the context menustrip. I am not able to differentiate whether "Add" or "Delete" was clicked. Currently I am using the "ItemClicked" event on the ContextMenuStrip to execute my piece of code in the event handler for "Add" but this evemt also gets raised when "Delete" is clicked. Any help would be appreciated.

Thanks, Viren

A: 

Instantiate your context menu strip. In that you will add your three ToolstripMenuItems. Each toolstrip menu item will have it's own OnClick method. Change the visibility property of an item depending on what your context requires.

dboarman