Back to Devexpress

Generate Multi-Level Diagrams

windowsforms-405020-controls-and-libraries-diagrams-data-binding-functionality-generate-multi-level-diagrams.md

latest3.5 KB
Original Source

Generate Multi-Level Diagrams

  • Jul 02, 2024
  • 2 minutes to read

Both DiagramDataBindingController and DiagramOrgChartController allow you to generate diagrams with composite items: item lists, multi-level containers, etc.

View Example: Generate Diagrams with Grouped Items

Use one of the following properties to generate a multi-level diagram:

DiagramDataBindingControllerBase.ItemsPathSet this property to the name of the data field that contains the collection of nested data items.DiagramDataBindingControllerBase.ItemsSelector

Use this property to dynamically return collections of nested items based on custom logic.

csharp
diagramDataBindingController1.ItemsSelector = new ItemsSelector();

public class ItemsSelector : IChildrenSelector {
    public IEnumerable<object> GetChildren(object parent) {
        if (parent is Department item)
            return item.Employees;
        else {
            //...
        }
    }
}
vb
diagramDataBindingController1.ItemsSelector = New ItemsSelector()

Public Class ItemsSelector
    Implements IChildrenSelector

    Public Function GetChildren(ByVal parent As Object) As IEnumerable(Of Object) Implements IChildrenSelector.GetChildren
        If TypeOf parent Is Department Then
            Return CType(parent, Department).Employees
        ElseIf
            ' ...
        End If

    End Function
End Class

You can use one of the following techniques to identify nested data items:

  • Assign the field name that uniquely identifies items to the DiagramDataBindingControllerBase.KeyMember property. Use this technique if the field name is the same for all nested levels.

  • Assign an object that returns item unique identifiers based on custom logic to the DiagramDataBindingControllerBase.KeySelector property. Use this technique if root and nested items have different identifier fields or to specify unique identifiers conditionally.

To generate different items based on the nested level, choose items from TemplateDiagram in the DiagramDataBindingControllerBase.GenerateItem event handler.

The DiagramControl automatically arranges child items if you place them inside a DiagramList. If you use a DiagramContainer as a parent item, you should arrange its nested items manually.

Refer to the following help topic for more information: Define and Configure Generated Diagram Items.