Back to Devexpress

How to: Recursively iterate through the child panels of a specific panel

windowsforms-5439-controls-and-libraries-docking-library-examples-how-to-recursively-iterate-through-the-child-panels-of-a-specific-panel.md

latest1.3 KB
Original Source

How to: Recursively iterate through the child panels of a specific panel

  • Nov 13, 2018

The following example demonstrates how to recursively iterate through the child panels of a specific panel. The IterateChildPanels method invokes the DoSomeOperation method for the last child of the specified panel (the child panel that doesn’t in turn contain any children).

csharp
using DevExpress.XtraBars.Docking;
// ...
void DoSomeOperation(DockPanel panel) {
   //...
}

void IterateChildPanels(DockPanel parentPanel) {
   if(parentPanel == null) return;
   for(int i = 0; i < parentPanel.Count; i++) {
      DockPanel childPanel = parentPanel[i];
      if(childPanel.Count == 0)
         DoSomeOperation(childPanel);
      else
         IterateChildPanels(childPanel);
   }
}
vb
Imports DevExpress.XtraBars.Docking
' ...
Sub DoSomeOperation(ByVal panel As DockPanel)
   '...
End Sub

Sub IterateChildPanels(ByVal parentPanel As DockPanel)
   If parentPanel Is Nothing Then Return
   Dim i As Integer
   For i = 0 To parentPanel.Count - 1
      Dim childPanel As DockPanel = parentPanel(i)
      If childPanel.Count = 0 Then
         DoSomeOperation(childPanel)
      Else
         IterateChildPanels(childPanel)
      End If
   Next
End Sub