473,385 Members | 1,942 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,385 software developers and data experts.

Build Menustrip at runtime

116 64KB
Hi,

I am trying to dynamically build up a menustrip at runtime from data in a string such as ...

Item1~Item2~Item3~Item4

where each item needs to be a subitem of the previous one in the menu.

I can convert the string to an array, loop through the items and get the data required.

However, I want to be able to efficiently add the sub items to their parent without continually looping through all the item names in the entire menu to see if and where the item already exists.

I know the following code will work but it has to be wildly inefficient when dealing with alot of entries as it looks through the entire menu system each time.

Expand|Select|Wrap|Line Numbers
  1. For j = 0 To myArray.Count - 1
  2. Dim thisid = myArray(j)
  3. Dim itemfound = 0
  4. Dim additem As New ToolStripMenuItem() With {.Text = itemid, .Name = j}
  5. For Each menuitem As ToolStripDropDownItem In mainMenu.DropDownItems
  6. If menuitem.Name = j Then
  7. menuitem.DropDownItems.Add(additem)
  8. itemfound = 1
  9. Exit For
  10. End If
  11. Next
  12. ' if not found then add it ... etc
  13.  
I would have thought a better way is to only look at the items in Item1 when adding Item2 (if no match then add it), then only look at items in Item2 for Item3 etc.

What I can't (yet again) work out is how to change the ForEach line to target the check for existing items in the previous item only. That is...

For Each menuitem As ToolStripDropDownItem In <PREVITEM>.DropDownItems

where <PREVITEM> is Item2 when looking to add Item3.

Does this make any sense at all? :)

Thanks
Mar 15 '13 #1

✓ answered by robertybob

Ok I have isolated this problem to being able to dynamically determine the parent item.

So for the first item added I can use

Expand|Select|Wrap|Line Numbers
  1. For Each subitem As ToolStripDropDownItem In DirectCast(mainMenu.Items(Item1), ToolStripDropDownItem).DropDownItems
  2.  
For the next one I need to alter 'mainMenu.Items' to 'Item1.DropDownItems' and so on...

Not sure how best to do that dynamically.

2 2276
robertybob
116 64KB
Actually, typing this out might have helped :)

Am currently trying DirectCast(mainMenu.Items(previtem), ToolStripDropDownItem).DropDownItems to see it thats it.

Will let you know it solved
Mar 15 '13 #2
robertybob
116 64KB
Ok I have isolated this problem to being able to dynamically determine the parent item.

So for the first item added I can use

Expand|Select|Wrap|Line Numbers
  1. For Each subitem As ToolStripDropDownItem In DirectCast(mainMenu.Items(Item1), ToolStripDropDownItem).DropDownItems
  2.  
For the next one I need to alter 'mainMenu.Items' to 'Item1.DropDownItems' and so on...

Not sure how best to do that dynamically.
Mar 15 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Colin Chudyk | last post by:
Hi, Here is my situation. Can anyone provide insight? I have developed a database in Access 2002. I am planning to distribute it as a split MDE (front) / MDB (back) to be used by the Access...
1
by: B&C | last post by:
Hello, I'm searching a runtime to read access databases on computers which doesn't have access installed. I found this runtime for access 2000, but I would prefer to use the access 97 "reader"....
9
by: Lawrence Oluyede | last post by:
I have a list of strings and i'd like to build up an enum from them... is there a way to do that? Thanks in advance. -- Lawrence "Rhymes" Oluyede http://loluyede.blogspot.com
5
by: Alvo von Cossel I | last post by:
hi, i have a modern looking application without the cotrolbox-bar because i've created my own. i have a restore down button with an image that has a grey background. if the user has a different...
4
by: Leon | last post by:
I am building an application that used the placement of panel controls at runtime. Inside of these panels I would like to add multiple buttons. This is part of a scheduling application that I will...
10
by: Lauren Wilson | last post by:
I have a desperate short term need for a way to install Access 2003 runtime on client computers. I have the proper license to do so but I cannot seem to find the files to do it like we did with...
0
by: academic | last post by:
Using ToolStripManager.Merge(ToolStrip,ToolStrip) I've been able to merge a MenuStrip into a MenuStrip but never a ContextMenuStrip into a MenuStrip. From the docs it seems to me I should be...
1
by: =?Utf-8?B?cGF0cmlja2RyZA==?= | last post by:
Hi guys! I have built a custom pager for my datagrids like in the picture: http://i173.photobucket.com/albums/w65/patrickdrd/dev/grid.jpg I would like to move that inside the datagrid (on...
1
by: ngrTerry | last post by:
I have a menustrip on my form which I add two options on it at runtime Dim t As ToolStripItem t.Text = "Option1" Me.mnuOrigins.DropDownItems.Add(t) t.Text = "Option2"...
12
by: Rotsey | last post by:
Hi, I have not had a good answer to this question. I put a menustrip on a form and so it is a main menu in affect. Now I put a webbrowser control on the form and set it dock fill. Of...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...

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.