Home All Groups Group Topic Archive Search About

how to get parent control of the context menu stip

Author
30 Aug 2006 12:06 PM
Lucky
hi guys,
i'm working on the context menu for the controls.
the problem i'm facing right now is like this :
i want to use one context menu for more then one controls lets say i
want to use one context menu for 3 treeview controls as 3 of them
shares same type of menu.
what i'm not able to do is, i can not idetify which control has invoke
the context menu's event. let say one of the treeview control has
invoke an event "Reset" from the context menu. all i need to do is, to
find out which treeview has invoked the event and needs to refill the
treeview control.

i tried to find out how to get the parent control but i failed to do
so.

tools
c#.net 2.0 (VS.NET 2005)

can anyone give me any kind of suggestion on this.

thanks,
Lucky

Author
30 Aug 2006 2:01 PM
Larry Lard
Lucky wrote:
Show quoteHide quote
> hi guys,
> i'm working on the context menu for the controls.
> the problem i'm facing right now is like this :
> i want to use one context menu for more then one controls lets say i
> want to use one context menu for 3 treeview controls as 3 of them
> shares same type of menu.
> what i'm not able to do is, i can not idetify which control has invoke
> the context menu's event. let say one of the treeview control has
> invoke an event "Reset" from the context menu. all i need to do is, to
> find out which treeview has invoked the event and needs to refill the
> treeview control.
>
> i tried to find out how to get the parent control but i failed to do
> so.

In the ContextMenuStrip's Opening event, set a form-level private
variable to the ContextMenuStrip's SourceControl property. This is the
control that invoked the context menu. Then in the Reset item's handler,
you will be able to see who wants to be reset.

I wanted to avoid using a variable, and just put the SourceControl in
the *menu strip's* Tag property, but I couldn't work out how to get from
a ToolStripMenuItem to its containing menu - can anyone enlighten me?


--
Larry Lard
larryl***@googlemail.com
The address is real, but unread - please reply to the group
For VB and C# questions - tell us which version
Author
30 Aug 2006 2:42 PM
Mudhead
Private Sub ContextMenuStrip1_Opening(ByVal sender As Object, ByVal e As _
System.ComponentModel.CancelEventArgs) Handles ContextMenuStrip1.Opening

Debug.WriteLine(ContextMenuStrip1.SourceControl.Name.ToString)

End Sub


Show quoteHide quote
"Lucky" <tushar.n.pa***@gmail.com> wrote in message
news:1156939608.207354.91500@i3g2000cwc.googlegroups.com...
> hi guys,
> i'm working on the context menu for the controls.
> the problem i'm facing right now is like this :
> i want to use one context menu for more then one controls lets say i
> want to use one context menu for 3 treeview controls as 3 of them
> shares same type of menu.
> what i'm not able to do is, i can not idetify which control has invoke
> the context menu's event. let say one of the treeview control has
> invoke an event "Reset" from the context menu. all i need to do is, to
> find out which treeview has invoked the event and needs to refill the
> treeview control.
>
> i tried to find out how to get the parent control but i failed to do
> so.
>
> tools
> c#.net 2.0 (VS.NET 2005)
>
> can anyone give me any kind of suggestion on this.
>
> thanks,
> Lucky
>