Hello all,
I have dynamic controls all associated with a single ContextMenuStri p. For
each menu item I have click event method. For each event I have cast sender
to ToolStripMenuIt em 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
contextmenustri p 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...ToolS tripDropDownMen u" to
"System...Conte xtMenuStrip." So in the case of a sub menu I changed the cast
to ToolStripDropDo wnMenu.
ToolStripMenuIt em TlStrip = (ToolStripMenuI tem)sender;
ToolStripDropDo wnMenu temp = (ToolStripDropD ownMenu)TlStrip .Owner;
TlStrip = (ToolStripMenuI tem)temp.OwnerI tem;
ContextMenuStri p Mnu = (ContextMenuStr ip)TlStrip.Owne r;
Using above code Mnu.SourceContr ol is always null.
What am I doing wrong?
--
Best Regards
"Failure is the opportunity to begin again more intelligently" – Henry Ford