Protected Sub GenerateMainMenu()
Dim addItem As Boolean
Dim ds As DataSet = GetMenuItems()
'Setup Menu
Dim topGroup As New MenuGroup(RadMenu1)
topGroup.Flow = PresentationDirection.Horizontal
topGroup.ExpandDirection = ExpandDirection.Down
RadMenu1.RootGroup = topGroup
For Each dbRow As DataRow In ds.Tables(0).Rows
addItem = False
'Top level rows have a null parentItem
'We will catch all the top items then query their children to build the menu
If dbRow.IsNull("parentItem") Then
If Not IsDBNull(dbRow("roles")) Then
addItem = CheckRole(dbRow("roles"))
Else
addItem = True
End If
End If
If addItem Then
Dim item As New MenuItem(topGroup)
CreateItem(item, dbRow)
RecursivelyPopulate(dbRow, item)
topGroup.AddItem(item)
End If
Next dbRow
End Sub
Private Sub RecursivelyPopulate(ByRef parentRow As DataRow, ByRef parentItem As MenuItem)
Dim childRow As DataRow
Dim addItem As Boolean
Dim childGroup As MenuGroup
For Each childRow In parentRow.GetChildRows("ItemRelation")
addItem = False
'instantiate group if necessary, we're doing it in the loop since we only want the group if there are child items
If IsNothing(childGroup) Then
childGroup = New MenuGroup(parentItem)
childGroup = parentItem.AddChildGroup()
childGroup.Flow = PresentationDirection.Vertical
End If
If Not IsDBNull(childRow("roles")) Then
addItem = CheckRole(childRow("roles"))
Else
addItem = True
End If
If addItem Then
Dim item As New MenuItem(childGroup)
CreateItem(item, childRow)
RecursivelyPopulate(childRow, item)
childGroup.AddItem(item)
End If
Next childRow
End Sub