I am using a ContextMenuStrip in a WinForm project. I have added two item in it at design time- 1) Add Focus and 2) Remove Focus. In runtime I am adding few dropdown items in "Add Focus" item. Problem is, I am getting null when trying to retrieve source control name.
Here is my code:
ToolStripDropDownItem dropDownItem = sender as ToolStripDropDownItem;
ToolStripMenuItem mainItem = dropDownItem.OwnerItem as ToolStripMenuItem;
ContextMenuStrip contextMenuStrip = mainItem.Owner as ContextMenuStrip;
Control control =contextMenuStrip.SourceControl; //getting null here
What is the problem in this code? Am I missing something here ?