Groups | Blog | Home
all groups > vb.net controls > june 2006 >

vb.net controls : Creating a dynamic menustrip


Adria Grau Rovira
6/29/2006 9:48:01 AM
Hello,

I'm trying to create a dynamic menustrip, the toolstripitems are in the
DataBase SQLSERVER, and I have this code:


For Each dtrow In ds.Tables("Vis_Menu").Rows
'MsgBox(dtrow("id_Menu"))
str = dtrow("fldOrden")
If str.Contains(".") Then 'Es un submenu


Else
Me.MenuStrip1.Items.AddRange(New
System.Windows.Forms.ToolStripItem() {Me.OpcionMenu})
Me.MenuStrip1.Size = New System.Drawing.Size(292, 24)
Me.MenuStrip1.TabIndex = 0
Me.MenuStrip1.Name = "MENUSTRIP"

Me.OpcionMenu.Text = dtrow("fldOrden")
Me.OpcionMenu.Name = dtrow("fldNombre")
Me.OpcionMenu.Size = New System.Drawing.Size(152, 22)
End If

Next

But it's only show the last option menu.

¿Can anybody help me???

Thanks.
Adria Grau Rovira
7/17/2006 11:21:01 PM
Thank you, it works good.

[quoted text, click to view]
GhostInAK
7/17/2006 11:21:37 PM
Hello Adria,

Because Me.OpcionMenu is an object that doesn't change. The menustrip detects
that you already added something that points to OpcionMenu and it just updates
it's reference. You want to do something like:

Dim tMenuItem as ToolStripItem = Nothing

For blahblahblah
tMenuItem = New ToolStripItem
' Set tMenuItem's properties here
MenuStrip1.Items.Add(tMenuItem)
Next


-Boo


[quoted text, click to view]

AddThis Social Bookmark Button