Hi,
I am using the follwoing code to generate Menustrip at runtime.
-
Dim dgv1 As DataGridView
-
dgv1 = Me.MenuDataGridView
-
ReadMenuInGridView(dgv1)
-
Dim MItems As New SortedList(Of String, ToolStripMenuItem)
-
For Each dgr As DataGridViewRow In dgv1.Rows
-
Dim MItem As New ToolStripMenuItem()
-
MItem.Text = dgr.Cells("item_title").Value
-
MItem.Tag = dgr.Cells("item_key").Value
-
MItems.Add("M" & dgr.Cells("itemid").Value, MItem)
-
If dgr.Cells("parent_itemid").Value = 0 Then
-
Me.GUMenuStrip.Items.Add(MItem)
-
AddHandler MItem.Click, AddressOf Me.MenuClick
-
ElseIf MItems.ContainsKey("M" & dgr.Cells("parent_itemid").Value) Then
-
MItems.Item("M" & dgr.Cells("parent_itemid").Value).DropDownItems.Add(MItem)
-
AddHandler MItem.Click, AddressOf Me.MenuClick
-
End If
-
Next
-
Where the sub "ReadMenuInGridView" passes the DGV by reference and populates it with the menu item from the database.
My question is,, the program as it is in the form listed above works fine (where I have a DGV "MenuDataGridView" created at design time), however, if I want to make it 100% dynamic and use a DGV created at run time I will not get the menu? Actually the program will not get in to the For loop?
Simply to do that we can replace the first 2 statement with:
-
Dim dgv1 As New DataGridView
-
'dgv1 = Me.MenuDataGridView
-
Any ideas?