Imports Infragistics.Win
Imports Infragistics.Win.UltraWinSchedule
Imports Infragistics.Win.UltraWinSchedule.CalendarCombo
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim info As String = "The descendant elements of the control's main UIElement are: " + vbCrLf + vbCrLf
Me.EnumerateChildElements(Me.ultraCalendarCombo1.UIElement, info)
' Display the UIElement hierarchy in a message box
MessageBox.Show(info, "EnumerateUIElements", MessageBoxButtons.OK)
End Sub
Private Sub EnumerateChildElements(ByVal element As UIElement, ByRef info As String)
'----------------------------------------------------------------------------------------------------
' UIElement
'
' Enumerates the specified UIElement's child elements to display
' the element hierarchy
'----------------------------------------------------------------------------------------------------
Dim level As Integer = Me.GetElementLevel(element)
Dim tabChar As String = String.Empty
Dim i As Integer
For i = 0 To level
tabChar += Chr(9)
Next
' Increment the level for the next iteration, if any
level += 1
' Iterate the specified element's ChildElements collection,
Dim child As UIElement
For Each child In element.ChildElements
' Output each child element's type name
info += tabChar + child.ToString() + vbCrLf
' Call this function recursively to get each child's children, etc.
Me.EnumerateChildElements(child, info)
Next
End Sub
' Returns the "generation" of the specified UIElement; that is, the
' number of ancestor UIElements it has
Private Function GetElementLevel(ByVal element As UIElement)
Dim level As Integer
Dim parentElement As UIElement = element.Parent
' Increment 'level' until we hit a null parent
While Not parentElement Is Nothing
level += 1
parentElement = parentElement.Parent
End While
Return level
End Function