Project: Medical note creation program
Language: VB.NET 2003 (Academic Version)
I already posted a question related to this project about a week ago-- thanks for those who responded!
I am currently trying to figure out a bit of a puzzle. I have a TreeView control on a form. When I right click on a node, the underlying procedure determines if it's a valid node; if so, it displays a context menu. Before the menu displays, it pulls up the first five or less items from an associated Access table and places these as menu items in the context menu.
For instance, if I right click on the "Left Ear" node, which is valid, the code looks at the table, finds two Left Ear entries, and places those in the menu. This part works well.
My problem right now is if I right click on another node, the previously inserted menu items remain, and the new right click adds the new node's entries to the menu. What I'm looking for is a way to remove previous custom entries so the menu only contains what it is supposed to.
I have a feeling I can name the menu items as I insert them. By doing this I can then reference them during the Popup event and use the Remove method to clear them out before inserting the new results. In other words, if I am able to apply the name mitCustomItem1, mitCustomItem2, and so forth, then during the Popup event I can loop through mitCustomItems 1 through 5 and Remove them if they exist.
Does anyone have an idea of how I'd turn this thought process into code? I have the concept, but my knowledge is shaky, so I'd appreciate any help anyone can provide!!!
Rhett
Depopulate Custom Menu Items from a Context MenuHow do I remove menu items at Popup?
Page 1 of 1
3 Replies - 2571 Views - Last Post: 09 July 2006 - 03:15 AM
Replies To: Depopulate Custom Menu Items from a Context Menu
#2
Re: Depopulate Custom Menu Items from a Context Menu
Posted 07 July 2006 - 10:18 AM
Language: VB .NET 2003 Academic
I think I figured out the question from the previous post, but think I now have another context menu-related problem.
I am trying to figure out how to create a variable string that can then be converted to a MenuItem, as illustrated in the following code:
I feel like I'm so close, but I've been stuck on this for a while. Is there a way to convert this string to a menu item? My sanity appreciates any advice or assistance it can get!
Rhett
I think I figured out the question from the previous post, but think I now have another context menu-related problem.
I am trying to figure out how to create a variable string that can then be converted to a MenuItem, as illustrated in the following code:
Dim i as Integer = 0
' RecordCount is declared elsewhere and is the result of how many records are returned from a backend table; assume RecordCount = 2
Do Until i = RecordCount
Dim x As int16 = 3
Dim findingString As String
Dim newMenuItem As String = "menuItem" & x
' Trouble area: how do I get newMenuItem to a MenuItem? Error message reads, "Value of type 'String' cannot be
' converted to 'System.Windows.Forms.MenuIem'.
Dim currentMenuItem As MenuItem = newMenuItem
findingString = ds.Tables("tblFindingsResults").Rows(i).Item(0)
currentMenuItem.Text = findingString
ctxContextMenu.MenuItems.Add(currentMenuItem)
i += 1
Loop
I feel like I'm so close, but I've been stuck on this for a while. Is there a way to convert this string to a menu item? My sanity appreciates any advice or assistance it can get!
Rhett
This post has been edited by rhett.moeller: 07 July 2006 - 10:38 AM
#3
Re: Depopulate Custom Menu Items from a Context Menu
Posted 07 July 2006 - 10:54 AM
May have to do with the object type...try
Dim currentMenuItem As MenuItem currentMenuItem = New MenuItem(newMenuItem)
#4
Re: Depopulate Custom Menu Items from a Context Menu
Posted 09 July 2006 - 03:15 AM
Thanks-- worked like a charm. I knew there had to be a way to force a String into a MenuItem, but was trying to do it in one line instead of two.
I appreciate the response!
Rhett
I appreciate the response!
Rhett
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|