I am using ContextMenuStrip in a WinForm project. I added two elements at this time of development: 1) Add focus and 2) Remove focus. At runtime, I add a few drop-down elements to the Add Focus element. The problem is that I get null when trying to get the name of the control source.
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? Did I miss something?
source share