473,372 Members | 1,062 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,372 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 2668
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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

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.