By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 777 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

ContextMenuStrip owner

P: n/a
In my program I dynamically create treeViews and dynamically add nodes to them.
To each node I attach ContextMenuStrip which suppose allow delete selected
node
e.t.c.

How from inside click event handling function to find which node was selected?
sender is set to ToolStripItem clicked.
Oct 5 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi lenusia,

You can retrieve the source by retrieving the ContextMenuStrip from the
ToolStripItem. You can retrieve the source control (the treeview you are
looking for) from the ContextMenuStrip.SourceControl. Like:
ToolStripMenuItem tsItem = (ToolStripMenuItem)sender;
ContextMenuStrip cMenuStrip = (ContextMenuStrip)tsItem.Owner;
Control theSourceControl = cMenuStrip.SourceControl;
TreeView myTreeView = (TreeView)theSourceControl;
MessageBox.Show(myTreeView.Name);

Note: you realy should check your objects before making explicit casts,
unless you are 100% shure nothing else could have raised the event.

Regards,

Nico
"Lenusia" wrote:
In my program I dynamically create treeViews and dynamically add nodes to them.
To each node I attach ContextMenuStrip which suppose allow delete selected
node
e.t.c.

How from inside click event handling function to find which node was selected?
sender is set to ToolStripItem clicked.
Oct 5 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.