473,396 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Inherited Treeview control with dynamic context menu.

Hi all, I'm just wondering if any one can help me with this development
issue I'm having. I've created a customized treeview control to handle the
particular tasks to which I'll be using it. Within the control I'm
dynamically creating a context menu and assigning it to the ContextMenu
property of the control -- think of this like the default context menu for
standard textboxes -- the context menu has a number of menu items that
reflect certain operations: add/edit/delete etc.

I have NO problems creating the actual menu itself, and in the test
application it displays correctly with all the items I've added to it. What
I DO have a problem with is that I cannot seem to access the events
associated with the menu like you would on normal form.

Here are some code snippets to illustrate:

DECLARATION:
Friend WithEvents __InternalContextMenu As New ContextMenu
ROUTINE TO CREATE THE MENU:
Private Sub CreateContextMenu()
Try
'add items to the context menu
With Me.__InternalContextMenu
.MenuItems.Add("Add Node Type A")
.MenuItems.Add("Add Node Type B")
.MenuItems.Add("Add Node Type C")
.MenuItems.Add("Add Node Type D")
.MenuItems.Add("-")
.MenuItems.Add("Delete Node Type A")
.MenuItems.Add("Delete Node Type B")
.MenuItems.Add("Delete Node Type C")
.MenuItems.Add("Delete Node Type D")
End With

'Set the MyTreeView ContextMenu property
'to use this default one:
Me.ContextMenu = Me.__InternalContextMenu
Catch ex As Exception
Dim ErrHandler As New ErrorLog(ex, MyAppPath())
Exit Sub
End Try
End Sub

The routine is being called from the Treeview's constructor.

QUESTION:
How do I Add event handler[s] to deal with click events on the context menu?

Any help from you pros out there would be very, very much appreciated.

--
Message posted via http://www.dotnetmonster.com
Nov 21 '05 #1
1 2675
I believe this should help you:
Private Sub CreateContextMenu()
Dim cm As New ContextMenu
Dim m As MenuItem
m = cm.MenuItems.Add("Test1")
AddHandler m.Click, AddressOf ContextMenuHandler

m = cm.MenuItems.Add("Test2")
AddHandler m.Click, AddressOf ContextMenuHandler
End Sub
Private Sub ContextMenuHandler(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Select Case CType(sender, MenuItem).Text
Case "Test1"
Case "Test2"
End Select
End Sub

"Chris Murphy via DotNetMonster.com" <fo***@nospam.DotNetMonster.com> wrote
in message news:e9******************************@DotNetMonste r.com...
Hi all, I'm just wondering if any one can help me with this development
issue I'm having. I've created a customized treeview control to handle the
particular tasks to which I'll be using it. Within the control I'm
dynamically creating a context menu and assigning it to the ContextMenu
property of the control -- think of this like the default context menu for
standard textboxes -- the context menu has a number of menu items that
reflect certain operations: add/edit/delete etc.

I have NO problems creating the actual menu itself, and in the test
application it displays correctly with all the items I've added to it. What I DO have a problem with is that I cannot seem to access the events
associated with the menu like you would on normal form.

Here are some code snippets to illustrate:

DECLARATION:
Friend WithEvents __InternalContextMenu As New ContextMenu
ROUTINE TO CREATE THE MENU:
Private Sub CreateContextMenu()
Try
'add items to the context menu
With Me.__InternalContextMenu
.MenuItems.Add("Add Node Type A")
.MenuItems.Add("Add Node Type B")
.MenuItems.Add("Add Node Type C")
.MenuItems.Add("Add Node Type D")
.MenuItems.Add("-")
.MenuItems.Add("Delete Node Type A")
.MenuItems.Add("Delete Node Type B")
.MenuItems.Add("Delete Node Type C")
.MenuItems.Add("Delete Node Type D")
End With

'Set the MyTreeView ContextMenu property
'to use this default one:
Me.ContextMenu = Me.__InternalContextMenu
Catch ex As Exception
Dim ErrHandler As New ErrorLog(ex, MyAppPath())
Exit Sub
End Try
End Sub

The routine is being called from the Treeview's constructor.

QUESTION:
How do I Add event handler[s] to deal with click events on the context menu?
Any help from you pros out there would be very, very much appreciated.

--
Message posted via http://www.dotnetmonster.com

Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Peter Zentner | last post by:
Hi all, if I assign a context menu to a treeview and popup the contextmenu with the APP-key the context menu appears in the center of the treeview control and not at the selected treenode. Is...
4
by: Aaron Queenan | last post by:
How can I use the designer to add a context menu to a class which inherits from a control, e.g. treeview, without adding the context menu to a form? For example, to add a context menu with...
5
by: SoKool | last post by:
Can anyone point me to a site where I can get a free treeview control to use in ASP .NET or any tutorial that can help me build my own treeview control. I intend to use a treeview to generate a...
1
by: Shailendra Batham | last post by:
Hey guys I am using the IE Web controls treeview control. I popuplate the treeview with XML and it looks fine........... my question is how can I add a right click popup menu to the treeview...
5
by: A-PK | last post by:
Hi, I am using treeview as my menu. my menu is like the following + Users & Groups - Users -Groups + Departmenuts - Engineering
4
by: Andrew Robinson | last post by:
I am using a TreeView to perform navigation and have a few nodes that need to generate a popup menu. For this, I use the SelectedNodeChanged event and then add the relevant "window.open" script to...
2
by: Claire | last post by:
I've a treeview control containing a root node with several children on a windows form. I select a node with a left mouse button click. I then select one of the other nodes with right mouse click...
0
by: divya1949 | last post by:
Create a windows c# application which will Read a xml file and populate nodes in the treeview. 1 On selection of treenode display the child nodes of that node in listview control 2. ...
1
by: Phill W. | last post by:
What's the "proper" way of handling this? I have a base Control that offers a small set of options via its ContextMenu. I've now inherited from this and would like to add additional items to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.