Skip to main content
All docs
V24.1

Generate Multi-Level Diagrams

  • 2 minutes to read

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

WPF Diagram - Generate Containers with Shapes

View Example: Generate Diagrams with Grouped Items

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

DiagramDataBindingControllerBase.ItemsPath
Set 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.

diagramDataBindingController1.ItemsSelector = new ItemsSelector();

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

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.

    diagramDataBindingController1.KeyMember = "ItemId";
    
  • 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.

    diagramDataBindingController1.KeySelector = new KeySelector();
    
    public class KeySelector : IKeySelector {
        object IKeySelector.GetKey(object obj) {
            if (obj is Department department)
                return department.DepartmentId;
            else if (obj is Employee employee)
                return employee.EmployeeId;
            else {
                //...
            }
        }
    }
    

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.