ContextMenuStrip

I am adding right click function on individual treeView nodes in my C # code. Options such as Add, Delete, Rename should appear when the user right-clicks on these tree nodes. Now, depending on the clicked node, I populate the menu using the following statememnts:

contextMenuStrip1.Items.Add ("Add");

Then if I right click on other nodes I use the following:

contextMenuStrip1.Items.Add ("Rename");

There are some nodes where both items should appear: contextMenuStrip1.Items.Add ("Add"); contextMenuStrip1.Items.Add ("Delete");

How can I write separate event handlers for add and remove if both exist in the context of menustrip. I cannot tell if "Add" or "Remove" was clicked. I am currently using the "ItemClicked" event in the ContextMenuStrip to execute my piece of code in the event handler for "Add", but this evemt is also raised when the "Delete" is clicked. Any help would be appreciated.

Thanks, Viren

+2


source to share


1 answer


Play context menu. In this case, you will add three ToolstripMenuItems. Each toolbar menu item will have its own OnClick method. Change the element's visibility property depending on what your context requires.



+2


source







All Articles