Prev: Is there anything you feel you DON'T know about C#?
Next: Shocking mistake with comparitor function by Microsoft programmers!
From: Dom on 3 Mar 2010 12:19 I have severall treeview controls on my form, and each has the contextmenustrip property set to mnuMain. That is, if you right-click on any tree, you get the same contextmenu. Is there some way, in mnuMain_Opening, that I can tell WHICH tree is opening the menu? Dom
From: Jean Lussier on 3 Mar 2010 15:44 You need to use the ".SourceControl" property in the "Opening" event of the MenuStrip. In the MSDN doc I found the following example that seems to work in my VS2005 version: Jean Lussier Montreal (Canada) -------------------------------------------------------------------------------------- Sub cms_Opening(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) ' Acquire references to the owning control and item. Dim c As Control = fruitContextMenuStrip.SourceControl Dim tsi As ToolStripDropDownItem = fruitContextMenuStrip.OwnerItem ' Clear the ContextMenuStrip control's ' Items collection. fruitContextMenuStrip.Items.Clear() ' Check the source control first. If Not (c Is Nothing) Then ' Add custom item (Form) fruitContextMenuStrip.Items.Add(("Source: " + c.GetType().ToString())) ElseIf Not (tsi Is Nothing) Then ' Add custom item (ToolStripDropDownButton or ToolStripMenuItem) fruitContextMenuStrip.Items.Add(("Source: " + tsi.GetType().ToString())) End If ' Populate the ContextMenuStrip control with its default items. fruitContextMenuStrip.Items.Add("-") fruitContextMenuStrip.Items.Add("Apples") fruitContextMenuStrip.Items.Add("Oranges") fruitContextMenuStrip.Items.Add("Pears") ' Set Cancel to false. ' It is optimized to true based on empty entry. e.Cancel = False End Sub "Dom" <dolivastro(a)gmail.com> wrote in message news:e5fab2e2-43f7-44af-aefa-09cb68305e20(a)q23g2000yqd.googlegroups.com... > I have severall treeview controls on my form, and each has the > contextmenustrip property set to mnuMain. That is, if you right-click > on any tree, you get the same contextmenu. Is there some way, in > mnuMain_Opening, that I can tell WHICH tree is opening the menu? > > Dom
From: Dom on 4 Mar 2010 10:27
On Mar 3, 3:44 pm, "Jean Lussier" <nos...(a)nospam.com> wrote: > You need to use the ".SourceControl" property in the "Opening" event of the > MenuStrip. > In the MSDN doc I found the following example that seems to work in my > VS2005 version: > > Jean Lussier > Montreal (Canada) > > -------------------------------------------------------------------------------------- > Sub cms_Opening(ByVal sender As Object, ByVal e As > System.ComponentModel.CancelEventArgs) > > ' Acquire references to the owning control and item. > Dim c As Control = fruitContextMenuStrip.SourceControl > Dim tsi As ToolStripDropDownItem = fruitContextMenuStrip.OwnerItem > > ' Clear the ContextMenuStrip control's > ' Items collection. > fruitContextMenuStrip.Items.Clear() > > ' Check the source control first. > If Not (c Is Nothing) Then > ' Add custom item (Form) > fruitContextMenuStrip.Items.Add(("Source: " + > c.GetType().ToString())) > ElseIf Not (tsi Is Nothing) Then > ' Add custom item (ToolStripDropDownButton or ToolStripMenuItem) > fruitContextMenuStrip.Items.Add(("Source: " + > tsi.GetType().ToString())) > End If > > ' Populate the ContextMenuStrip control with its default items. > fruitContextMenuStrip.Items.Add("-") > fruitContextMenuStrip.Items.Add("Apples") > fruitContextMenuStrip.Items.Add("Oranges") > fruitContextMenuStrip.Items.Add("Pears") > > ' Set Cancel to false. > ' It is optimized to true based on empty entry. > e.Cancel = False > End Sub > > "Dom" <dolivas...(a)gmail.com> wrote in message > > news:e5fab2e2-43f7-44af-aefa-09cb68305e20(a)q23g2000yqd.googlegroups.com... > > > > > I have severall treeview controls on my form, and each has the > > contextmenustrip property set to mnuMain. That is, if you right-click > > on any tree, you get the same contextmenu. Is there some way, in > > mnuMain_Opening, that I can tell WHICH tree is opening the menu? > > > Dom- Hide quoted text - > > - Show quoted text - Thanks. Just what I needed. |