View Implementations

The default view for presenting graphs, class GraphControl, is hierarchy-aware by default. All application-level features described in the section called “Class GraphControl”, like, e.g., clipboard functionality or Undo/Redo are available for grouped graphs out-of-the-box.

Class HierarchyTreeView

Generic type HierarchyTreeView<T> helps in presenting the tree-like hierarchy modeled by an IHierarchy implementation in a System.Windows.Forms.TreeView.

When used for displaying a hierarchy of nodes that is held by an IHierarchy implementation, the type parameter is accordingly bound to model item type INode. Example 3.8, “Setting up a HierarchyTreeView” presents the setup of a HierarchyTreeView for displaying the hierarchical organization of a grouped graph.

Example 3.8. Setting up a HierarchyTreeView

// 'graph' is of type yWorks.yFiles.UI.Model.IGraph.

// Retrieve the hierarchy of nodes.
IHierarchy<INode> hierarchy = graph.Get<IHierarchy<INode>>();

// Display the hierarchy in a TreeView control.
if (hierarchy != null) {
  // 'treeView' is a System.Windows.Forms.TreeView.
  new HierarchyTreeView<INode>(hierarchy, treeView);
}

HierarchyTreeView adds the nodes of the hierarchy to the TreeView and uses the first node label as the descriptive text to be displayed. Figure 3.11, “Graph view provided by HierarchyTreeView” shows a TreeView placed on the left side inside an application's window that displays the hierarchical organization of the folding-enabled graph from a managed view.

Figure 3.11. Graph view provided by HierarchyTreeView

Graph view provided by HierarchyTreeView.

In tutorial demo application GraphEditorForm further aspects of presenting a graph in a TreeView can be observed.