Discovering which item is clicked in a dynamic context menu?

Streen

Member
Joined
Apr 7, 2010
Messages
16
Programming Experience
3-5
I have a DataGrid and I want each of its cells to display its own customized ContextMenuStrip.
So I have a handler that listens to clicks on the datagrid. It opens an existing ContextMenuStrip, clears it and fills it with strings using

Me.ContextMenuStrip1.Items.Add(fileName)

So far so good. That works.
Then I have a handler that listens to

Handles ContextMenuStrip1.ItemClicked

and I want certain actions to be taken depending on which menu item is clicked. Here lies my problem. How do I find out which item was clicked?

I suppose the answer is real simple, but I cant seem to find it :(
 
All event handlers have two parameters: 'sender' and 'e'. The 'sender' is the object that raised the event; in your case, ContextMenuStrip1. The 'e' parameter contains the data for the event, which varies from event to event. It's logical that you would need to know which item was clicked in the ItemClicked event handler, so I'll wager that the 'e' parameter provides that information. Check what members it has and I think you'll find that there's a property that returns the item.
 
Back
Top