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

Dynamically Adding MenuStrip and its MenuItems in VB.Net 2005 ?

How can I dynamically Add menuStrip and its menuItems through code using
VB.Net 2005 ?

Best Regards,

Luqman
Apr 18 '07 #1
6 34569

"Luqman" <pe*******@cyber.net.pkwrote in message
news:ez**************@TK2MSFTNGP03.phx.gbl...
How can I dynamically Add menuStrip and its menuItems through code using
VB.Net 2005 ?

Best Regards,

Luqman

A good way to discover the code needed to do what you want is to add a
MenuStrip and the items you want using the GUI designer, then look at the
generated code. That will be the code you need to do the same thing at run
time.
Apr 18 '07 #2
On Apr 18, 7:26 am, "Luqman" <pearls...@cyber.net.pkwrote:
How can I dynamically Add menuStrip and its menuItems through code using
VB.Net 2005 ?

Best Regards,

Luqman
Here's some code that will create a menu with 3 main choices with 4
drop downs each.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim menu As New MenuStrip()
For i As Integer = 0 To 2
Dim item As New ToolStripMenuItem(String.Format("Menu Item
{0}", i.ToString()))
For j As Integer = 0 To 3
Dim innerItem As New
ToolStripMenuItem(String.Format("Inner Menu Item {0}", j.ToString()))
item.DropDownItems.Add(innerItem)
Next
menu.Items.Add(item)
Next
Me.Controls.Add(menu)
End Sub

Thanks,

Seth Rowe

Apr 18 '07 #3
Thanks Dear, thats exactly what I wanted, but how can I set the Tag Property
of the Items added in DropDownItems.

Say, I also want to set the innerItem.Tag=1234, innerItem.Name="myMenuItem"

item.DropDownItems.Add(innerItem)
Best Regards,

Luqman
"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11**********************@y80g2000hsf.googlegr oups.com...
On Apr 18, 7:26 am, "Luqman" <pearls...@cyber.net.pkwrote:
>How can I dynamically Add menuStrip and its menuItems through code using
VB.Net 2005 ?

Best Regards,

Luqman

Here's some code that will create a menu with 3 main choices with 4
drop downs each.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim menu As New MenuStrip()
For i As Integer = 0 To 2
Dim item As New ToolStripMenuItem(String.Format("Menu Item
{0}", i.ToString()))
For j As Integer = 0 To 3
Dim innerItem As New
ToolStripMenuItem(String.Format("Inner Menu Item {0}", j.ToString()))
item.DropDownItems.Add(innerItem)
Next
menu.Items.Add(item)
Next
Me.Controls.Add(menu)
End Sub

Thanks,

Seth Rowe

Apr 18 '07 #4
On Apr 18, 10:11 am, "Luqman" <pearls...@cyber.net.pkwrote:
Thanks Dear, thats exactly what I wanted, but how can I set the Tag Property
of the Items added in DropDownItems.

Say, I also want to set the innerItem.Tag=1234, innerItem.Name="myMenuItem"
item.DropDownItems.Add(innerItem)

Best Regards,

Luqman

"rowe_newsgroups" <rowe_em...@yahoo.comwrote in message

news:11**********************@y80g2000hsf.googlegr oups.com...
On Apr 18, 7:26 am, "Luqman" <pearls...@cyber.net.pkwrote:
How can I dynamically Add menuStrip and its menuItems through code using
VB.Net 2005 ?
Best Regards,
Luqman
Here's some code that will create a menu with 3 main choices with 4
drop downs each.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim menu As New MenuStrip()
For i As Integer = 0 To 2
Dim item As New ToolStripMenuItem(String.Format("Menu Item
{0}", i.ToString()))
For j As Integer = 0 To 3
Dim innerItem As New
ToolStripMenuItem(String.Format("Inner Menu Item {0}", j.ToString()))
item.DropDownItems.Add(innerItem)
Next
menu.Items.Add(item)
Next
Me.Controls.Add(menu)
End Sub
Thanks,
Seth Rowe
You just need to modify the item in the loop it is created in.

i.e.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim menu As New MenuStrip()
For i As Integer = 0 To 2
Dim item As New ToolStripMenuItem(String.Format("Menu Item
{0}", i.ToString()))
' Modify item here
item.Name = "myMenuItem"
For j As Integer = 0 To 3
Dim innerItem As New
ToolStripMenuItem(String.Format("Inner Menu Item {0}", j.ToString()))
' Modify inner item here
innerItem.Tag = 1234
item.DropDownItems.Add(innerItem)
Next
menu.Items.Add(item)
Next
Me.Controls.Add(menu)
End Sub

Thanks,

Seth Rowe

Apr 18 '07 #5
Ok I got it, thanks once again.

Best Regards,

Luqman

"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11*********************@o5g2000hsb.googlegrou ps.com...
On Apr 18, 10:11 am, "Luqman" <pearls...@cyber.net.pkwrote:
>Thanks Dear, thats exactly what I wanted, but how can I set the Tag
Property
of the Items added in DropDownItems.

Say, I also want to set the innerItem.Tag=1234,
innerItem.Name="myMenuItem"
item.DropDownItems.Add(innerItem)

Best Regards,

Luqman

"rowe_newsgroups" <rowe_em...@yahoo.comwrote in message

news:11**********************@y80g2000hsf.googleg roups.com...
On Apr 18, 7:26 am, "Luqman" <pearls...@cyber.net.pkwrote:
How can I dynamically Add menuStrip and its menuItems through code
using
VB.Net 2005 ?
>Best Regards,
>Luqman
Here's some code that will create a menu with 3 main choices with 4
drop downs each.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim menu As New MenuStrip()
For i As Integer = 0 To 2
Dim item As New ToolStripMenuItem(String.Format("Menu Item
{0}", i.ToString()))
For j As Integer = 0 To 3
Dim innerItem As New
ToolStripMenuItem(String.Format("Inner Menu Item {0}", j.ToString()))
item.DropDownItems.Add(innerItem)
Next
menu.Items.Add(item)
Next
Me.Controls.Add(menu)
End Sub
Thanks,
Seth Rowe

You just need to modify the item in the loop it is created in.

i.e.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim menu As New MenuStrip()
For i As Integer = 0 To 2
Dim item As New ToolStripMenuItem(String.Format("Menu Item
{0}", i.ToString()))
' Modify item here
item.Name = "myMenuItem"
For j As Integer = 0 To 3
Dim innerItem As New
ToolStripMenuItem(String.Format("Inner Menu Item {0}", j.ToString()))
' Modify inner item here
innerItem.Tag = 1234
item.DropDownItems.Add(innerItem)
Next
menu.Items.Add(item)
Next
Me.Controls.Add(menu)
End Sub

Thanks,

Seth Rowe

Apr 19 '07 #6
OK, now that you've got the submenu items built, how do you handle the
submenu item click event, since you have no way of writing specific menu
item event handlers?

Thanks,
Dean S
"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11*********************@o5g2000hsb.googlegrou ps.com...
On Apr 18, 10:11 am, "Luqman" <pearls...@cyber.net.pkwrote:
>Thanks Dear, thats exactly what I wanted, but how can I set the Tag
Property
of the Items added in DropDownItems.

Say, I also want to set the innerItem.Tag=1234,
innerItem.Name="myMenuItem"
item.DropDownItems.Add(innerItem)

Best Regards,

Luqman

"rowe_newsgroups" <rowe_em...@yahoo.comwrote in message

news:11**********************@y80g2000hsf.googleg roups.com...
On Apr 18, 7:26 am, "Luqman" <pearls...@cyber.net.pkwrote:
How can I dynamically Add menuStrip and its menuItems through code
using
VB.Net 2005 ?
>Best Regards,
>Luqman
Here's some code that will create a menu with 3 main choices with 4
drop downs each.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim menu As New MenuStrip()
For i As Integer = 0 To 2
Dim item As New ToolStripMenuItem(String.Format("Menu Item
{0}", i.ToString()))
For j As Integer = 0 To 3
Dim innerItem As New
ToolStripMenuItem(String.Format("Inner Menu Item {0}", j.ToString()))
item.DropDownItems.Add(innerItem)
Next
menu.Items.Add(item)
Next
Me.Controls.Add(menu)
End Sub
Thanks,
Seth Rowe

You just need to modify the item in the loop it is created in.

i.e.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim menu As New MenuStrip()
For i As Integer = 0 To 2
Dim item As New ToolStripMenuItem(String.Format("Menu Item
{0}", i.ToString()))
' Modify item here
item.Name = "myMenuItem"
For j As Integer = 0 To 3
Dim innerItem As New
ToolStripMenuItem(String.Format("Inner Menu Item {0}", j.ToString()))
' Modify inner item here
innerItem.Tag = 1234
item.DropDownItems.Add(innerItem)
Next
menu.Items.Add(item)
Next
Me.Controls.Add(menu)
End Sub

Thanks,

Seth Rowe

Jul 8 '07 #7

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

Similar topics

3
by: Aaron Ackerman | last post by:
I have a bound combobox the appears on a cell within the column of my bound grid when the user clicks on a cell n(In my vb.net WinForm app). I am trying to allow the adding of an item to that bound...
11
by: Steven D'Aprano | last post by:
Suppose I create a class with some methods: py> class C: .... def spam(self, x): .... print "spam " * x .... def ham(self, x): .... print "ham * %s" % x .......
0
by: Sinisa Ruzin | last post by:
Hi all, I had problem with dynamically adding/removing controls;ascx, Controls.Add(Page.LoadControl... in the same page of the IBuySpy portal. ASP.NET, C#. I added buttons to the main ASCX loaded...
3
by: Ben Dewey | last post by:
Okay, so I have a base Page class called ArticlesPageBase. This base class has reads in an overridable ArticleId and Loads the data into a Panel object in the ContentPlaceHolder of the Master. ...
5
by: J | last post by:
I am having problems dynamically adding more than one event handler to an input. I have tried the Javascript included at the bottom. The lines inp.attachEvent('onkeyup',...
5
by: Liquidtouch | last post by:
I'm not much of a HTML or Javascript programmer but have a little experience just hacking away at it. I am creating a HTML application and would like to be able to add or remove rows of a table....
0
by: kyungdongkim | last post by:
Hi, I have a dynamically generated MenuStrip following this example: http://www.codeproject.com/useritems/Dynamic_MenuStrip.asp Basically the menu strip allows users to save and load reports. ...
4
by: Lewis Holmes | last post by:
Hi I have the following situation in one of my asp.net pages. The user can add multiple table rows to a form by selecting a button. These rows can contain asp.net controls. When this button is...
1
by: vivek kapile | last post by:
Title:Dynamically adding table row with a checkbox using JavaScript Author:Vivek Kapile Email:snipped Language:JavaScript Platform:JavaScript in ASP.net Technology:Used in ASP.net...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
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...

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.