In a similar manor to the previous post, the following code can be used in the controller for event handlers for ToolStripMenuItem’s on a ContextMenuStrip.
Unfortunately, due to a bug found by Dan, this code will not work for any ToolStripMenuItem’s that are in sub-menus in the ContextMenuStrip. Even when combined with the code from the previous post to recursively search for the top level ContextMenuStrip control, the SourceControl property is null.
public void UserSearchView_menuitemDeleteUser_Click(object sender, EventArgs e)
{
Application.DoEvents();
ToolStripMenuItem theDeleteUserMenuItem =
sender as ToolStripMenuItem;
ContextMenuStrip theContextMenuStrip =
theDeleteUserMenuItem.Owner as ContextMenuStrip;
UserSearchView theParentView =
theContextMenuStrip.SourceControl.FindForm()
as UserSearchView;
if (null != theParentView)
{
...
}
}
June 12th, 2007