Tree List View
A tree and a grid in one control: rows that nest, expand and collapse like a tree view, laid out
in sortable, resizable, editable columns like a DataGridView.
Assembly
| Assembly | Binarymission.WinForms.Controls.BinaryTreeListView.dll |
| Root namespace | Binarymission.WinForms.Controls.TreeControls |
| Target frameworks | .NET Framework 4.8, .NET 6 / 8 / 10 |
| Depends on | BinaryComboBox, BinaryDatePicker, BinaryExtendedText, BinaryOfficeColorPicker, BinaryToolTip, BinaryTreeViewComboBox, BinaryUpDown |
Overview
Use it wherever data has both a hierarchy and several facts per row: a project plan with
owners, due dates and progress, a file system with sizes and dates, a chart of accounts with
balances, a bill of materials with quantities and costs. It is a DataGridView
underneath, so fonts, cell styles, column sizing, selection and editing work as they do in any
grid.
Columns
Add the columns before any rows. Exactly one column should be a
BinaryTreeListViewColumn: that column carries the tree – the indent, the expand
glyph, the connecting lines and the node's image or check box. It can be at any position. The
other columns can be any DataGridViewColumn, including the editing columns made
for this control: BinaryTreeListViewDatePickerColumn,
BinaryTreeListViewNumericUpDownColumn, BinaryTreeListViewComboBoxColumn,
BinaryTreeListViewOffice2007ColorPickerColumn,
BinaryTreeListViewExtendedTextBoxColumn and
BinaryTreeListViewNumericExtendedTextBoxColumn.
Nodes
Every row is a BinaryTreeListViewNode. Build the tree through
Nodes, never through the grid's own rows: Nodes.Add(...) takes one value per
column, in column order, and returns the new node, whose own BinaryTreeListViewNode.Nodes
takes its children the same way. A node starts collapsed; call
BinaryTreeListViewNode.Expand() or ExpandAllNodes to open it. Keep your
own object with the row in Tag. To build the tree from a table
instead, set HierarchicalDataSource to a DataTable whose first three
columns are UID, ID and ParentID.
Expanding and collapsing
The user opens and closes a node by clicking its glyph, by double-clicking the tree cell
(ExpandCollapseNodeOnDoubleClick), and with Shift+Right and Shift+Left
(ExpandCollapsingOfNodesLevel). Each change raises
BinaryTreeListViewNodeExpanding or BinaryTreeListViewNodeCollapsing
first, which can cancel it or – for expanding – add the children at that moment, and then
BinaryTreeListViewNodeExpanded or BinaryTreeListViewNodeCollapsed.
Rows that are inside a collapsed node are not in the grid at all, so the grid's row indices count
only the rows on show.
Sorting
Turn on AllowUserToSortColumns and a click on a heading sorts by that column,
a second click reverses it and a third puts the original order back; SortNodesByColumn
does the same from code. Siblings are sorted within their parent at every level, so the tree keeps
its shape. The grid's own column sorting is not used: every column is made
NotSortable as it is added.
Editing
Cells are edited as in any grid, starting the way CellEditingMode says – set
that rather than DataGridView.EditMode, which the control switches as the user
clicks between the tree's glyph area and the text. F2 always starts an edit. The special editing
columns show their editor's chrome – a spinner, a drop-down button, a colour swatch – on every
row while SpecialColumnCellsToDisplayEditingControlOnCellsAlways is on, so the grid
reads as a form.
Appearance
The connecting lines are drawn in LineDrawingColor and
LineDrawingDashStyle, or not at all (DrawNodeConnectingLines). The
expand glyph is the system tree glyph unless both ExpandImage and
CollapseImage are set. Each node shows an image (NodeImage,
BinaryTreeListViewNode.Image), or a check box or radio button
(SetUpNodeControlType). UseBuiltInRendering paints the headings and
rows in gradients, and ShouldDrawFrame gives the control a rounded border with a
soft shadow.
Drag and drop
With EnableAutomaticBuiltInDragDrop on, the user can drag a node, with
everything beneath it, onto another node to make it that node's child, or onto the empty area
below the last row to make it a top-level node. For your own drag and drop, set
Control.AllowDrop and handle ItemDrag.
The control can also run as a plain grid with the same appearance features: set
ControlDataDisplayMode to ControlDataDisplayMode.ListView
before adding columns, and use ordinary columns and the grid's own DataSource.
Getting started
A project plan on a form, built in code. The first column is the tree; the others show an
owner, a due date that edits with a calendar, and progress that edits with a spinner. Each node
keeps its WorkItem in Tag.
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using Binarymission.WinForms.Controls.TreeControls;
public sealed class WorkItem
{
public string Title { get; set; }
public string Owner { get; set; }
public DateTime Due { get; set; }
public decimal PercentDone { get; set; }
}
public sealed class ProjectPlanForm : Form
{
private readonly BinaryTreeListView plan = new BinaryTreeListView();
private readonly Label status = new Label();
public ProjectPlanForm()
{
Text = "Website relaunch";
ClientSize = new Size(820, 460);
plan.Dock = DockStyle.Fill;
plan.AllowUserToSortColumns = true;
plan.LineDrawingColor = Color.Silver;
plan.LineDrawingDashStyle = DashStyle.Dot;
plan.ShouldDrawFrame = true;
plan.FrameFocusedBorderColor = Color.SteelBlue;
// Columns first: the tree column, then one column per fact.
plan.Columns.Add(new BinaryTreeListViewColumn { Name = "Task", HeaderText = "Task", FillWeight = 260 });
plan.Columns.Add(new DataGridViewTextBoxColumn { Name = "Owner", HeaderText = "Owner" });
plan.Columns.Add(new BinaryTreeListViewDatePickerColumn { Name = "Due", HeaderText = "Due", Format = BinaryDatePickerFormat.Short });
plan.Columns.Add(new BinaryTreeListViewNumericUpDownColumn { Name = "Done", HeaderText = "Done %", Maximum = 100 });
BinaryTreeListViewNode design = AddTask(plan.Nodes, new WorkItem { Title = "Design", Owner = "Priya Shah", Due = new DateTime(2026, 11, 6), PercentDone = 60 });
AddTask(design.Nodes, new WorkItem { Title = "Wireframes", Owner = "Priya Shah", Due = new DateTime(2026, 10, 23), PercentDone = 100 });
AddTask(design.Nodes, new WorkItem { Title = "Visual design", Owner = "Tom Hughes", Due = new DateTime(2026, 11, 6), PercentDone = 20 });
BinaryTreeListViewNode build = AddTask(plan.Nodes, new WorkItem { Title = "Build", Owner = "Ana Costa", Due = new DateTime(2026, 12, 11), PercentDone = 10 });
AddTask(build.Nodes, new WorkItem { Title = "Checkout", Owner = "Ana Costa", Due = new DateTime(2026, 12, 4), PercentDone = 0 });
plan.ExpandAllNodes();
// Keep a summary task open while it still has work outstanding.
plan.BinaryTreeListViewNodeCollapsing += (sender, e) =>
{
e.Cancel = ((WorkItem)e.Node.Tag).PercentDone < 100;
};
plan.SelectionChanged += (sender, e) =>
{
BinaryTreeListViewNode node = plan.CurrentNode;
status.Text = node == null ? string.Empty : ((WorkItem)node.Tag).Title + " - " + ((WorkItem)node.Tag).Owner;
};
status.Dock = DockStyle.Bottom;
Controls.Add(plan);
Controls.Add(status);
}
private static BinaryTreeListViewNode AddTask(BinaryTreeListViewNodesCollection nodes, WorkItem item)
{
// One value per column, in column order.
BinaryTreeListViewNode node = nodes.Add(item.Title, item.Owner, item.Due, item.PercentDone);
node.Tag = item;
return node;
}
}API reference
Binarymission.WinForms.Controls.TreeControls
enum BinaryDatePickerFormat | How a BinaryTreeListViewDatePickerColumn shows its dates. |
class BinaryTreeListView | A tree and a grid in one control: rows that nest, expand and collapse like a tree view, laid out in sortable, resizable, editable columns like a DataGridView. |
enum NodeControlType | What a node shows in its tree cell between the expand glyph and the text: its image, a check box or a radio button. Used with SetUpNodeControlType. |
class BinaryTreeListViewCell | The cell of the tree column: a text cell that also draws the node's indent, connecting lines, expand glyph and image or check box, and turns clicks on them into tree actions. |
enum BinaryTreeListViewCellClickedArea | The part of a tree cell the user clicked, as reported by BinaryTreeListViewCellClicked. |
class BinaryTreeListViewCellClickedEventArgs | Provides data for the BinaryTreeListViewCellClicked event: the node, cell and column clicked, which part of the cell, and a way to cancel the control's response. |
delegate BinaryTreeListViewCellClickedHandler | Represents the method that handles BinaryTreeListViewCellClicked. |
class BinaryTreeListViewCellInfo | The image settings of a node's tree cell - its image and whether to show it - with a text, as one object. |
class BinaryTreeListViewColumn | The column that carries the tree: its cells draw each node's indent, connecting lines, expand glyph and image or check box beside the text. |
class BinaryTreeListViewComboBoxCell | The cell of a BinaryTreeListViewComboBoxColumn, edited with a Binarymission combo box. |
class BinaryTreeListViewComboBoxColumn | A column whose cells are edited with a Binarymission combo box, which can drop down a multi-column list with sorting, grouping, filtering and export. |
class BinaryTreeListViewDatePickerCell | The cell of a BinaryTreeListViewDatePickerColumn: shows a date in the column's format and edits it with a drop-down calendar. |
class BinaryTreeListViewDatePickerColumn | A column of dates, edited with a Binarymission BinaryDatePicker and its drop-down calendar. |
class BinaryTreeListViewEvent | The base of the data for the events raised after a node has opened or closed: it carries the node. |
class BinaryTreeListViewExtendedTextBoxCell | A cell of a BinaryTreeListViewExtendedTextBoxColumn: it shows its value as text and is edited in a BinaryExtendedText. |
class BinaryTreeListViewExtendedTextBoxColumn | A BinaryTreeListView column whose cells are edited in a BinaryExtendedText - a text box with a flat, coloured border. |
class BinaryTreeListViewNode | A node of a BinaryTreeListView: one row of the grid, with its own child nodes, which the control shows indented beneath it when it is open. |
class BinaryTreeListViewNodeCollapsedEventArgs | Provides data for the BinaryTreeListViewNodeCollapsed event: the node that has closed. |
delegate BinaryTreeListViewNodeCollapsedEventHandler | Represents the method that handles BinaryTreeListViewNodeCollapsed. |
class BinaryTreeListViewNodeCollapsingEventArgs | Provides data for the BinaryTreeListViewNodeCollapsing event: the node about to close, and a way to keep it open. |
delegate BinaryTreeListViewNodeCollapsingEventHandler | Represents the method that handles BinaryTreeListViewNodeCollapsing. |
class BinaryTreeListViewNodeExpandedEventArgs | Provides data for the BinaryTreeListViewNodeExpanded event: the node that has opened. |
delegate BinaryTreeListViewNodeExpandedEventHandler | Represents the method that handles BinaryTreeListViewNodeExpanded. |
class BinaryTreeListViewNodeExpandingEventArgs | Provides data for the BinaryTreeListViewNodeExpanding event: the node about to open, and a way to keep it closed. |
delegate BinaryTreeListViewNodeExpandingEventHandler | Represents the method that handles BinaryTreeListViewNodeExpanding. |
class BinaryTreeListViewNodesCollection | The children of a node, or the top-level nodes of a BinaryTreeListView: the collection through which the tree is built. |
class BinaryTreeListViewNumericExtendedTextBoxCell | A cell of a BinaryTreeListViewNumericExtendedTextBoxColumn: it shows its value as text and is edited in a BinaryNumericExtendedText. |
class BinaryTreeListViewNumericExtendedTextBoxColumn | A BinaryTreeListView column whose cells are edited in a BinaryNumericExtendedText - a box that accepts only numbers, with a flat, coloured border. |
class BinaryTreeListViewNumericUpDownCell | A cell of a BinaryTreeListViewNumericUpDownColumn: it holds a decimal, shows it with the column's decimal places and thousands separator, and is edited in a spinner. |
class BinaryTreeListViewNumericUpDownColumn | A BinaryTreeListView column of numbers - quantities, percentages, prices - edited in a spinner and held within a range. |
class BinaryTreeListViewOffice2007ColorPickerCell | A cell of a BinaryTreeListViewOffice2007ColorPickerColumn: it shows a colour as a swatch or a fill, and is edited in an Office-style palette. |
class BinaryTreeListViewOffice2007ColorPickerColumn | A BinaryTreeListView column of colours, each edited in an Office-style palette that drops down from the cell. |
enum BuiltInCustomRenderedTargetElement | The parts of a BinaryTreeListView the built-in renderer paints in gradients. |
enum CellInfoCheckStatus | Whether a node shows a check box or a radio button in its tree cell, and whether it is ticked. |
enum ColorPickerCellDrawingStyle | How a cell of a BinaryTreeListViewOffice2007ColorPickerColumn shows its colour while it is not being edited. |
enum ControlDataDisplayMode | Whether a BinaryTreeListView works as a tree list view or as a plain grid. |
enum ExpandCollapsingOfNodesLevel | Where the focus must be for Shift+Right and Shift+Left to open and close a node. |
class MultiColumnDropDownWindowConfiguration | The look of the header, footer and column headings of a BinaryTreeListViewComboBoxColumn's multi-column drop-down. |
class MultiColumnDropDownWindowConfigurationTypeConverter | Lets the Properties window expand a MultiColumnDropDownWindowConfiguration into its individual settings, instead of showing it as one value. |
enum NodeSortOrder | The order of sibling nodes in a tree built from HierarchicalDataSource with ShouldEnableLinkedRelationshipsTuning on. |
class SystemHelper | Reads icons for files and folders from the Windows shell, so that rows in a tree list view can show the same icons Explorer does. |
enum EnumFolderType | Whether to ask the system for the open or the closed variant of a folder icon. |
enum EnumIconSize | Which of the two shell icon sizes to ask the system for. |