Reputation: 11104
I have a ContextMenu
assigned to two ListView
s. How to know which ListView
it was used with so I can apply correct method? I guess sender
is important here but how do I use it? How to know what sender
is at this very moment?
private void contextMenuDokumentyDodaj_Click(object sender, EventArgs e) {
var dokumenty = new DocumentsGui(varKlienciID, varPortfelID);
dokumenty.Show();
dokumenty.FormClosed += varDocumentsGui_FormClosed;
}
Upvotes: 1
Views: 519
Reputation: 3360
ContextMenu.SourceControl
is your ticket.
http://msdn.microsoft.com/en-us/library/system.windows.forms.contextmenu.sourcecontrol.aspx
EDIT
ContextMenuStrip, you say?
http://msdn.microsoft.com/en-us/library/system.windows.forms.contextmenustrip.sourcecontrol.aspx
Upvotes: 1
Reputation: 18743
Did you try the following?
ListView listViewClicked = (ListView) sender;
EDIT (after comments)
The sender
is the ToolStripMenuItem
, so use a cast to get it, then use GetCurrentParent
method to get the ContextMenuStrip
containing the item, then use the SourceControl
property to get the control displaying your menu, as suggested by @sq33G:
ListView lv = ((ToolStripMenuItem) sender).GetCurrentParent().SourceControl;
Maybe you'll need also to cast the GetCurrentParent
return value to a ContextMenuStrip
.
Upvotes: 0