Hello all,
I have dynamic controls all associated with a single ContextMenuStrip. For
each menu item I have click event method. For each event I have cast sender
to ToolStripMenuItem to ContextMenuStip to use SourceControl to get the
control that initiated the event.
This all works well if the the menu items are one level deep on the
contextmenustrip control, but if I create a sub menu item doing the above
logic does not work.
First of all it gives a cast error of
"Unable to cast object of type "System...ToolStripDropDownMenu" to
"System...ContextMenuStrip." So in the case of a sub menu I changed the cast
to ToolStripDropDownMenu.
ToolStripMenuItem TlStrip = (ToolStripMenuItem)sender;
ToolStripDropDownMenu temp = (ToolStripDropDownMenu)TlStrip.Owner;
TlStrip = (ToolStripMenuItem)temp.OwnerItem;
ContextMenuStrip Mnu = (ContextMenuStrip)TlStrip.Owner;
Using above code Mnu.SourceControl is always null.
What am I doing wrong?
--
Best Regards
"Failure is the opportunity to begin again more intelligently" – Henry Ford