I’ve assigned a contextMenuStrip to the same contextual menu property of two ListBox controls.
I would like to determine which of them has activated the contextual menu.
Because I have to change some entries depending on which control was clicked at runtime.
private void copyNotesToClipboardStripMenu_Click(object sender, EventArgs e)
{
ListBox cntrl = conMenuNotes.SourceControl as ListBox;
//cntrl does not contain info about which ListBox was clicked :((
//check which ListBox was clicked
if (/*oneListBox*/)
{
//do something
}
if(/*anotherLiskBox*/)
{
//do something
}
}
As i read another posts it should be the name of the clicked control in the Label property.
I see that cntrl.Label is null
What i’m doing wrong ?
Advice me how to resolve this ambiguity.
Thank you!
I found a result that works fine for me
The property Name of controlSelected object contains the name of control which has activated the contextual menu.