OrgChart
Wisej.NET 4.2.0+
The OrgChart control draws a hierarchy as cards joined by connectors: an organization chart of people, a tree of departments or cost centres, or a breakdown of sites and assets. Each node shows a portrait (or initials), a name, and a secondary line such as a job title; branches can be expanded and collapsed, and the user can drag a node onto a new parent when you allow it.
Where a TreeView lists a hierarchy as indented text, the org chart lays it out in two dimensions, so the shape of the hierarchy is what the reader sees first.
For a complete list of properties, methods, and events, see the API documentation.
Features
Nodes and Hierarchy
The Nodes collection is flat: each OrgNode has an Id and a ParentId, and the chart builds the tree from them. Nodes can be added in any order, children before their parents. A node whose ParentId is empty or unknown is shown as a root, so several roots form a forest. The collection rejects duplicate ids and cycles; removing a parent turns its children into roots. Siblings follow collection order.
Each node also has a Text, a SubText, an Image or an ImageSource for the portrait, a Tone (Neutral, Primary, Success, Warning, or Danger) that colours the initials when there is no portrait, and a server-only Tag. Changing a property of a node updates the chart.
Layout
ChartLayout sets the direction in which levels grow: TopDown (the default) places children below their parent, LeftRight places them to its right, which suits deep and narrow hierarchies.
Expanding and Collapsing
Nodes with children show a button under the card with the number of direct reports, which expands or collapses the branch. CollapseBelow sets the depth at which branches start collapsed: -1 (the default) expands everything, 0 shows only the roots, 1 shows the roots and their children. SetExpanded(node, expanded) opens or closes a single branch and raises ExpandChanged when the state changes, as the button does; IsExpanded(node) reads the effective state. Changing CollapseBelow discards the branch-by-branch overrides.
Reparenting
With AllowDragReparent set to true, the user can drag a node onto a new parent. Nothing changes on the drop alone: the server raises NodeMoving, which you can cancel, then updates ParentId and raises NodeMoved. MoveNode(node, parent) proposes the same move from code, through the same events; pass null as the parent to promote a node to a root. Drops that would create a cycle are refused.
Setting ParentId directly changes the model without raising either event.
Custom Node Templates
Set NodeTemplate to the type of a UserControl to replace the standard card with your own design. The chart creates one instance per visible node, sizes the node from the template's Size, sets its Tag to the OrgNode, and disposes it when the node is hidden or removed. Implement IOrgNodeTemplate to receive the node in its Node property, and updates to it.
Events
NodeClick and NodeDoubleClick receive an OrgNodeEventArgs with the Node. NodeMoving and NodeMoved receive an OrgNodeMoveEventArgs with the Node, its OldParent, and the proposed Parent (null for a root). ExpandChanged receives an OrgNodeExpandEventArgs with the Node and the new Expanded state.
How To
Build an Organization Chart
this.orgChart1.CollapseBelow = 2;
this.orgChart1.Nodes.Add(new OrgNode { Id = "ops", Text = "Nadia Ferrari", SubText = "VP Operations" });
this.orgChart1.Nodes.Add(new OrgNode { Id = "wh", ParentId = "ops", Text = "Marcus Chen", SubText = "Warehouse Manager", Tone = MeterTone.Success });
this.orgChart1.Nodes.Add(new OrgNode { Id = "log", ParentId = "ops", Text = "Leila Costa", SubText = "Logistics Manager" });
this.orgChart1.Nodes.Add(new OrgNode { Id = "sup", ParentId = "ops", Text = "Tom Becker", SubText = "Support Lead", Tone = MeterTone.Warning });
this.orgChart1.Nodes.Add(new OrgNode { Id = "wh-1", ParentId = "wh", Text = "Ana Silva", SubText = "Shift Supervisor" });
// Show the portrait of an employee from a URL.
this.orgChart1.Nodes[0].ImageSource = "https://intranet.example.com/photos/nferrari.jpg";
Load the Chart from Your Data
foreach (var employee in hrService.GetEmployees(departmentId))
{
this.orgChart1.Nodes.Add(new OrgNode
{
Id = employee.EmployeeId.ToString(),
ParentId = employee.ManagerId?.ToString() ?? "",
Text = employee.FullName,
SubText = employee.JobTitle,
Tag = employee
});
}
Confirm a Move Before Committing It
this.orgChart1.AllowDragReparent = true;
private void orgChart1_NodeMoving(object sender, OrgNodeMoveEventArgs e)
{
// Only managers can receive direct reports.
var manager = e.Parent?.Tag as Employee;
e.Cancel = manager == null || !manager.IsManager;
}
private void orgChart1_NodeMoved(object sender, OrgNodeMoveEventArgs e)
{
var employee = (Employee)e.Node.Tag;
hrService.ChangeManager(employee.EmployeeId, ((Employee)e.Parent.Tag).EmployeeId);
AlertBox.Show($"{employee.FullName} now reports to {e.Parent.Text}.");
}
Open the Details of a Node
private void orgChart1_NodeDoubleClick(object sender, OrgNodeEventArgs e)
{
if (e.Node.Tag is Employee employee)
new EmployeeDetailsForm(employee).ShowDialog();
}
Advanced
JavaScript Widget
| Item | Description |
|---|---|
| Class name | "wisej.web.OrgChart" |
| Theme appearance | "orgchart"; the parts use "orgchart-node" (states "selected", "focused", "droptarget", "dragging"), "orgchart-avatar" (one state per tone), "orgchart-title", "orgchart-subtext", "orgchart-connector", "orgchart-expand" and "orgchart-drag-preview". See Themes. |