HypernovaDesktop Components · docs
Binarymission
WinForms › Tree List View › BinaryTreeListView

BinaryTreeListView

class.NET 6 / 8 / 10.NET Framework 4.8Binarymission.WinForms.Controls.TreeControls

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.

public partial class BinaryTreeListView : DataGridView

Inherits from / implements: DataGridView

Remarks

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.

Tip

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.

Examples

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;
    }
}

See also

Members at a glance

Constructors
BinaryTreeListViewCreates a tree list view with no columns and no nodes.
Properties
AllowDataErrorExceptionToBeThrownGets or sets whether a cell value that cannot be formatted or committed is reported as a DataGridView normally reports it.
AllowUserToAddRowsGets or sets whether the grid shows the row for adding a new row at the bottom.
AllowUserToDeleteRowsGets or sets whether the user can delete rows with the Delete key.
AllowUserToSortColumnsGets or sets whether clicking a column heading sorts the tree by that column: ascending, then descending, then back to the order the nodes were built in.
BuiltInCustomRenderedTargetElementGets or sets which parts of the grid the built-in renderer paints: the column headings, the row headings, the rows, or a combination.
BusyIndicatorTextGets or sets the message shown in the middle of the control while HierarchicalDataSource is being bound.
BusyIndicatorTextBackColorGets or sets the background colour of the message shown while HierarchicalDataSource is being bound.
BusyIndicatorTextFontGets or sets the font of the message shown while HierarchicalDataSource is being bound.
BusyIndicatorTextForeColorGets or sets the text colour of the message shown while HierarchicalDataSource is being bound.
CellBorderColorGets or sets the colour of the border round the current cell.
CellBorderDrawingColorGets or sets the colour of the cell borders the built-in renderer draws on the rows.
CellBorderWidthGets or sets the width of the border round the current cell.
CellEditingModeGets or sets how the user starts editing a cell. Set this instead of the grid's DataGridView.EditMode.
CollapseImageGets or sets the image drawn as the collapse glyph of an open node.
ColumnBackgroundDefaultCellStyleBackColorGets or sets the background colour a tinted column is given back when the pointer, or the current cell, leaves it.
ColumnBackgroundOnCellSelectionColorGets or sets the colour the column of the current cell is tinted in.
ColumnBackgroundOnMouseHoverColorGets or sets the colour the column under the pointer is tinted in.
ColumnHeaderBottomBorderColorGets or sets the colour of a rule drawn along the bottom of the column headings, parting them from the rows.
ColumnSeparatorDrawingColorGets or sets the colour of the line the built-in renderer draws between column headings.
ControlDataDisplayModeGets or sets whether the control works as a tree list view or as a plain grid with this control's appearance features.
CurrentNodeGets the node of the current cell – the row the user is on.
DepthForPreparingNodesWithChildrenGets or sets how many passes binding makes over HierarchicalDataSource to place rows whose parent comes after them in the table.
DrawColumnSeparatorWhenUsingBuiltinRenderingGets or sets whether the built-in renderer draws a line between column headings.
DrawGlassBackgroundHighlightingOnMouseEnterGets or sets whether the row under the pointer is highlighted.
DrawNodeConnectingLinesGets or sets whether lines are drawn joining each node to its parent and its siblings.
EnableAutomaticBuiltInDragDropGets or sets whether the user can rearrange the tree by dragging nodes with the mouse.
EnableCommitingEditWhenMovingFocusFromEditContextGets or sets whether an edit in progress is committed when the user clicks the glyph, check box or image area of a tree cell.
EnableExpandCollapsingOfNodesUponMouseClickOnReadOnlyTreeListViewNodeCellOrColumnGets or sets whether, in a read-only tree, a click anywhere in a node's tree cell opens or closes the node.
EndColorForRenderingColumnHeaderGets or sets the colour at the bottom or right of the gradient the built-in renderer fills the column headings with.
EndColorForRenderingRowGets or sets the colour at the bottom or right of the gradient the built-in renderer fills each cell of the rows with.
EndColorForRenderingRowHeaderGets or sets the colour at the bottom or right of the gradient the built-in renderer fills the row headings with.
ExpandCollapseNodeOnDoubleClickGets or sets whether double-clicking a node's cell in the tree column opens or closes the node.
ExpandCollapsingOfNodesLevelGets or sets where the focus must be for Shift+Right and Shift+Left to open and close a node.
ExpandImageGets or sets the image drawn as the expand glyph of a closed node that has children.
ExpandTargetDropNodeUponDragDropGets or sets whether the node a dragged node is dropped on is opened, with everything beneath it, so that the moved node can be seen in its new place.
FrameBorderColorGets or sets the colour of the frame's border.
FrameBorderThicknessGets or sets the thickness of the frame's border.
FrameCornerRadiusGets or sets the radius of the frame's rounded corners.
FrameFocusedBorderColorGets or sets the colour of the frame's border while the focus is in the control – on the grid or on a cell's editor.
FramePaddingGets or sets the space between the frame's border and the grid inside it.
FrameShadowColorGets or sets the colour of the frame's drop shadow.
FrameShadowDepthGets or sets how far the frame's shadow spreads.
FrameShadowOpacityGets or sets the strength of the frame's shadow where it is darkest, next to the border.
GlassBrushBottomHalfEndColorGets or sets the colour the hover highlight ends with – at the bottom of the row, or at its right when OrientationAspectForRenderingRow is horizontal.
GlassBrushBottomHalfStartColorGets or sets a colour kept for compatibility; the hover highlight does not use it.
GlassBrushLinearGradientFactorGets or sets a value kept for compatibility; the hover highlight does not use it.
GlassBrushTopHalfEndColorGets or sets a colour kept for compatibility; the hover highlight does not use it.
GlassBrushTopHalfStartColorGets or sets the colour the hover highlight starts with – at the top of the row, or at its left when OrientationAspectForRenderingRow is horizontal.
HierarchicalDataSourceGets or sets a table to build the whole tree from, in place of adding nodes in code.
HighlightOnlyTreeListCellDuringDragOverGets or sets whether only one cell, rather than the whole row, is coloured to show where a dragged node would be dropped.
IsChildDropDownShowingGets whether a date cell is being edited and its drop-down calendar is open.
LineDrawingColorGets or sets the colour of the lines that join the nodes.
LineDrawingDashStyleGets or sets the pattern of the lines that join the nodes: solid, dotted, dashed and so on.
NodeImageGets or sets the image shown beside every node's text, between the expand glyph and the text.
NodesGets the top-level nodes. This is where the tree is built.
NodesSortColumnGets the column the tree is sorted by.
NodesSortDirectionGets the direction the tree is sorted in.
NodesSortOrderGets or sets the order of sibling rows in a tree built from HierarchicalDataSource with ShouldEnableLinkedRelationshipsTuning on: ascending or descending by UID.
OptimiseLayoutRenderingDuringDragDropGets or sets whether layout is suspended while a dropped branch is moved, so that a large branch moves without the grid laying itself out for every row.
OrientationAspectForRenderingColumnHeaderGets or sets the direction of the gradient the built-in renderer fills the column headings with.
OrientationAspectForRenderingRowGets or sets the direction of the gradient the built-in renderer fills each cell of a row with, and of the hover highlight.
OrientationAspectForRenderingRowHeaderGets or sets the direction of the gradient the built-in renderer fills the row headings with.
RowSelectionBackColorDuringDragOverGets or sets the background colour of the row a dragged node is over – the node it would be dropped on.
RowSelectionForeColorDuringDragOverGets or sets the text colour of the row a dragged node is over.
RowTemplateGets or sets the row the grid copies for new rows.
RowsGets the grid's rows: the nodes that are on show, in display order.
ShouldDrawCellBorderWhenSelectedGets or sets whether the current cell is outlined with a border of its own while it is not being edited.
ShouldDrawColumnBackgroundUponCellSelectionGets or sets whether the column of the current cell is tinted in ColumnBackgroundOnCellSelectionColor.
ShouldDrawColumnBackgroundUponMouseHoveringGets or sets whether the column under the pointer is tinted in ColumnBackgroundOnMouseHoverColor.
ShouldDrawFrameGets or sets whether the control draws its own frame: a border with rounded corners, an inner padding and, optionally, a soft drop shadow, all inside its bounds.
ShouldDrawFrameShadowGets or sets whether the frame casts a soft drop shadow.
ShouldEnableFastCachingGets or sets whether binding makes a single pass over the data, rather than DepthForPreparingNodesWithChildren passes.
ShouldEnableLinkedRelationshipsTuningGets or sets whether rows from HierarchicalDataSource are placed in the order of their UID rather than the order of the table.
ShowNodeImageGets or sets whether the top-level nodes show their image.
SpecialColumnCellsToDisplayEditingControlOnCellsAlwaysGets or sets whether cells of the special editing columns show their editor's chrome on every row, not only on the cell being edited.
StartColorForRenderingColumnHeaderGets or sets the colour at the top or left of the gradient the built-in renderer fills the column headings with.
StartColorForRenderingRowGets or sets the colour at the top or left of the gradient the built-in renderer fills each cell of the rows with.
StartColorForRenderingRowHeaderGets or sets the colour at the top or left of the gradient the built-in renderer fills the row headings with.
UseBuiltInRenderingGets or sets whether the control paints the parts named by BuiltInCustomRenderedTargetElement itself, in gradients of the colours you choose, instead of leaving them to the grid.
VirtualModeGets or sets whether the grid asks for cell values as it needs them rather than holding them.
Methods
AboutShows the control's About box as a modal dialog.
BindToTreeListViewBuilds the tree from a table now, without setting HierarchicalDataSource.
ClearAllNodesRemoves every node, at every level, and every row from the control.
CollapseAllNodesCloses every node in the tree, at every level, leaving only the top-level nodes on show.
CollapseNodeCloses a node and, if asked, every node beneath it.
CollapseNodeCloses a node, taking its descendants off the grid.
DisposeReleases the nodes' rows and the control's other resources.
ExpandAllNodesOpens every node in the tree, at every level.
ExpandNodeOpens a node and, if asked, every node beneath it.
ExpandNodeOpens a node, showing its children.
GetAllSiblingsForThisNodeReturns the nodes that share a parent with the given node.
GetFlatListOfNodesGets every node in the tree, at every level, as one flat sequence.
GetFlatListOfNodesReturns every node beneath a node, at every level, as one flat sequence.
GetNodeAtReturns the node shown at a point in the control.
OnCellMouseDoubleClickRaises the DataGridView.CellMouseDoubleClick event, then opens or closes the node when ExpandCollapseNodeOnDoubleClick is on and the cell is in the tree column.
OnCellMouseDownRaises the DataGridView.CellMouseDown event, noting where a pressed column heading stood, so that a heading dragged to a new place is not also taken as a click to sort.
OnCellMouseEnterRaises the DataGridView.CellMouseEnter event, and moves the hover highlight to the row the pointer has entered.
OnCellMouseLeaveRaises the DataGridView.CellMouseLeave event, and clears the hover highlight from the row the pointer has left.
OnCellPaintingRaises the DataGridView.CellPainting event, then paints the parts the control draws itself: the built-in gradients and hover highlight, the sort glyph and the current cell's border.
OnColumnAddedRaises the DataGridView.ColumnAdded event, after making the new column NotSortable so that sorting is the control's own (see AllowUserToSortColumns).
OnColumnHeaderMouseClickRaises the DataGridView.ColumnHeaderMouseClick event, after sorting by the column when AllowUserToSortColumns is on.
OnColumnWidthChangedRaises the DataGridView.ColumnWidthChanged event, then paints any part of the control waiting to be painted.
OnDataErrorRaises the DataGridView.DataError event when AllowDataErrorExceptionToBeThrown is on; otherwise ignores the error.
OnFontChangedRaises the FontChanged event, and resizes rows that still have their default height so that the new font fits them.
OnHandleCreatedRaises the Control.HandleCreated event, and sizes rows that still have the default height to fit the control's font.
OnKeyDownRaises the Control.KeyDown event, and handles the control's own keys: Shift+Right and Shift+Left to open and close the current node, F2 to edit the current cell, and Enter to return to whole-row selection.
OnMouseDownRaises the Control.MouseDown event, notes the node under the pointer for ItemDrag, and restores CellEditingMode when the current cell is not in the tree column.
OnMouseLeaveRaises the Control.MouseLeave event, and clears any hover highlight.
OnMouseMoveRaises the Control.MouseMove event, and raises ItemDrag when a node is dragged far enough.
OnMouseUpRaises the Control.MouseUp event.
OnParentChangedRaises the Control.ParentChanged event, and starts watching the new parent's size so that the scroll bars are laid out again when it changes.
OnRowEnterRaises the DataGridView.RowEnter event, and returns the grid to whole-row selection, selecting the row entered.
OnRowsAddedRaises the DataGridView.RowsAdded event, after giving each node added its indent, and a height to suit the control's font.
OnSizeChangedRaises the Control.SizeChanged event.
SetUpNodeControlTypeGives every node now in the tree a check box, a radio button, or neither.
SortNodesByColumnSorts the tree by the values in a column – siblings within their parent, at every level, closed branches included – or, with SortOrder.None, puts back the order the nodes were built in.
WndProcProcesses the Windows messages sent to the control's window, reserving and painting the frame when ShouldDrawFrame is on.
Events
BinaryTreeListViewCellClickedOccurs when the user presses the mouse button on a cell of the tree column, before the control acts on the click.
BinaryTreeListViewNodeCollapsedOccurs after a node has closed and the rows beneath it have been taken out of the grid.
BinaryTreeListViewNodeCollapsingOccurs before an open node closes, whether the user closed it or code did; the closing can be cancelled.
BinaryTreeListViewNodeExpandedOccurs after a node has opened and its children have been added to the grid.
BinaryTreeListViewNodeExpandingOccurs before a node opens, whether the user opened it or code did; the opening can be cancelled.
ItemDragOccurs when the user starts dragging a node, for drag and drop you handle yourself.

Constructors

BinaryTreeListView

public BinaryTreeListView()

Creates a tree list view with no columns and no nodes.

Remarks

The control starts set up as a tree: whole-row selection, no row headers and no cell borders, rows that the user cannot add or delete, columns that fill the width (Fill) and that the user can resize and reorder, and F2 to edit.

Add a BinaryTreeListViewColumn and any other columns to DataGridView.Columns, then add nodes through Nodes.

Properties

AllowDataErrorExceptionToBeThrown

public bool AllowDataErrorExceptionToBeThrown

Gets or sets whether a cell value that cannot be formatted or committed is reported as a DataGridView normally reports it.

Value
false by default.
Remarks

With it off, such errors are ignored: DataGridView.DataError is not raised, no error dialog is shown and nothing is thrown.

With it on, the grid's own handling applies: DataGridView.DataError is raised, the grid shows its error dialog when nothing handles the event, and a handler can set ThrowException to have the exception thrown.

See also

AllowUserToAddRows

public new bool AllowUserToAddRows

Gets or sets whether the grid shows the row for adding a new row at the bottom.

Value
false by default. In ControlDataDisplayMode.TreeListView mode it stays false whatever is set; nodes are added through Nodes.
See also

AllowUserToDeleteRows

public new bool AllowUserToDeleteRows

Gets or sets whether the user can delete rows with the Delete key.

Value
false by default. In ControlDataDisplayMode.TreeListView mode it stays false whatever is set; remove nodes through Nodes.
See also

AllowUserToSortColumns

public bool AllowUserToSortColumns

Gets or sets whether clicking a column heading sorts the tree by that column: ascending, then descending, then back to the order the nodes were built in.

Value
false by default.
Default
false
Remarks

A plain row sort would scramble a tree, so this is not the grid's own sort – every column stays NotSortable. Siblings are sorted within their parent, at every level, and each parent keeps its children beneath it. The sorted heading shows a chevron pointing up or down. A heading dragged to a new place is moved, not sorted.

Turning it off while the tree is sorted puts the original order back. To sort from code, call SortNodesByColumn; to decide how two values compare, handle DataGridView.SortCompare.

See also

BuiltInCustomRenderedTargetElement

public BuiltInCustomRenderedTargetElement BuiltInCustomRenderedTargetElement

Gets or sets which parts of the grid the built-in renderer paints: the column headings, the row headings, the rows, or a combination.

Value
BuiltInCustomRenderedTargetElement.ColumnAndRowHeaders by default.
Remarks

Applies while UseBuiltInRendering is on. The rows are painted only for BuiltInCustomRenderedTargetElement.Row and BuiltInCustomRenderedTargetElement.All, so those are the settings that show the hover highlight and the cell borders in CellBorderDrawingColor. Row headings are hidden in a tree unless you turn on DataGridView.RowHeadersVisible.

Changing it does not repaint the control; call Control.Invalidate to see the change at once.

See also

BusyIndicatorText

public string BusyIndicatorText

Gets or sets the message shown in the middle of the control while HierarchicalDataSource is being bound.

Value
"Processing data... please wait..." by default. Setting null or an empty string is ignored and keeps the current message.
Remarks

The message, its colours and its font are read each time binding starts. It is not shown by BindToTreeListView.

See also

BusyIndicatorTextBackColor

public Color BusyIndicatorTextBackColor

Gets or sets the background colour of the message shown while HierarchicalDataSource is being bound.

Value
SystemColors.Window by default.
See also

BusyIndicatorTextFont

public Font BusyIndicatorTextFont

Gets or sets the font of the message shown while HierarchicalDataSource is being bound.

Value
CaptionFont by default.
See also

BusyIndicatorTextForeColor

public Color BusyIndicatorTextForeColor

Gets or sets the text colour of the message shown while HierarchicalDataSource is being bound.

Value
SystemColors.WindowText by default.
See also

CellBorderColor

public Color CellBorderColor

Gets or sets the colour of the border round the current cell.

Value
Color.Empty by default, which draws nothing; set a colour to see the border.
See also

CellBorderDrawingColor

public Color CellBorderDrawingColor

Gets or sets the colour of the cell borders the built-in renderer draws on the rows.

Value
SystemColors.WindowText by default.
Remarks

Drawn only when UseBuiltInRendering is on, BuiltInCustomRenderedTargetElement paints the rows (BuiltInCustomRenderedTargetElement.Row or BuiltInCustomRenderedTargetElement.All), and DataGridView.CellBorderStyle is one of Single, SingleHorizontal or SingleVertical. A tree starts with no cell borders (None), so set the border style as well.

Changing it does not repaint the control; call Control.Invalidate to see the change at once.

CellBorderWidth

public int CellBorderWidth

Gets or sets the width of the border round the current cell.

Value
In pixels; 0 by default, which draws the thinnest line. The width is used as given, not scaled for the display.
See also

CellEditingMode

public DataGridViewEditMode CellEditingMode

Gets or sets how the user starts editing a cell. Set this instead of the grid's DataGridView.EditMode.

Value
EditOnKeystrokeOrF2 by default.
Remarks

The control changes DataGridView.EditMode itself while the user works in the tree column, so that a click on a node's glyph or check box never starts an edit, and puts this value back afterwards. A value set on DataGridView.EditMode directly is therefore overwritten; one set here is kept, and applies at once.

Until this is set, or the user first clicks a cell, the grid starts editing on F2 only.

Example
// Only F2 starts an edit, so typing while a row is selected never changes a value by accident.
plan.CellEditingMode = DataGridViewEditMode.EditOnF2;

CollapseImage

public Image CollapseImage

Gets or sets the image drawn as the collapse glyph of an open node.

Value
null, the default, for the system tree glyph.
Remarks

Takes effect only when ExpandImage is set as well. The image is drawn 10 by 10 logical pixels. A node's own BinaryTreeListViewNode.CollapseImage takes precedence.

See also

ColumnBackgroundDefaultCellStyleBackColor

public Color ColumnBackgroundDefaultCellStyleBackColor

Gets or sets the background colour a tinted column is given back when the pointer, or the current cell, leaves it.

Value
The grid's DataGridView.DefaultCellStyle back colour when the control is created – SystemColors.Window unless changed.
Remarks

Set it to the column colour you want when nothing is tinted, if that is not the grid's default cell colour.

See also

ColumnBackgroundOnCellSelectionColor

public Color ColumnBackgroundOnCellSelectionColor

Gets or sets the colour the column of the current cell is tinted in.

Value
Color.Empty by default, which leaves the column in the grid's own background colour.
See also

ColumnBackgroundOnMouseHoverColor

public Color ColumnBackgroundOnMouseHoverColor

Gets or sets the colour the column under the pointer is tinted in.

Value
Color.Empty by default, which leaves the column in the grid's own background colour.
See also

ColumnHeaderBottomBorderColor

public Color ColumnHeaderBottomBorderColor

Gets or sets the colour of a rule drawn along the bottom of the column headings, parting them from the rows.

Value
Color.Empty, the default, for no rule. The rule is one logical pixel thick.
Default
Remarks

Drawn when UseBuiltInRendering is on and BuiltInCustomRenderedTargetElement includes the column headings. The built-in renderer paints its own background over the grid's heading border, so without a rule the headings end wherever their colour stops. Setting it repaints the control.

See also

ColumnSeparatorDrawingColor

public Color ColumnSeparatorDrawingColor

Gets or sets the colour of the line the built-in renderer draws between column headings.

Value
SystemColors.WindowText by default.
Remarks

Drawn when DrawColumnSeparatorWhenUsingBuiltinRendering is on and the built-in renderer paints the column headings. The line runs down the right-hand edge of each heading, two logical pixels short of its top and bottom. Changing it does not repaint the control; call Control.Invalidate to see the change at once.

See also

ControlDataDisplayMode

public ControlDataDisplayMode ControlDataDisplayMode

Gets or sets whether the control works as a tree list view or as a plain grid with this control's appearance features.

Value
ControlDataDisplayMode.TreeListView, the default, or ControlDataDisplayMode.ListView.
Remarks

Set it before adding columns or rows. In ControlDataDisplayMode.ListView mode a BinaryTreeListViewColumn cannot be added (adding one throws), setting HierarchicalDataSource is ignored, and AllowUserToAddRows and AllowUserToDeleteRows can be turned on.

The settings the constructor makes for a tree – whole-row selection, no row headers, no cell borders – are not undone by switching to ControlDataDisplayMode.ListView; set those grid properties yourself.

CurrentNode

public BinaryTreeListViewNode CurrentNode

Gets the node of the current cell – the row the user is on.

Value
The current node, or null when there is no current cell.
Remarks

Handle DataGridView.SelectionChanged or DataGridView.CurrentCellChanged to follow it as the user moves.

DepthForPreparingNodesWithChildren

public int DepthForPreparingNodesWithChildren

Gets or sets how many passes binding makes over HierarchicalDataSource to place rows whose parent comes after them in the table.

Value
25 by default.
Remarks

A table that lists every parent before its children needs one pass; the default allows for a tree up to 25 levels deep listed in any order. Rows not placed after the last pass are left out. ShouldEnableFastCaching overrides it with a single pass.

Setting it binds the data again. With no HierarchicalDataSource set, that removes every node from the control – nodes added in code included – so set it before adding nodes, or only on a bound tree.

See also

DrawColumnSeparatorWhenUsingBuiltinRendering

public bool DrawColumnSeparatorWhenUsingBuiltinRendering

Gets or sets whether the built-in renderer draws a line between column headings.

Value
false by default.
Remarks

Applies while UseBuiltInRendering is on and BuiltInCustomRenderedTargetElement includes the column headings. The line is drawn in ColumnSeparatorDrawingColor. Changing it does not repaint the control; call Control.Invalidate to see the change at once.

See also

DrawGlassBackgroundHighlightingOnMouseEnter

public bool DrawGlassBackgroundHighlightingOnMouseEnter

Gets or sets whether the row under the pointer is highlighted.

Value
true by default.
Remarks

The highlight is part of the built-in row painting, so it shows only while UseBuiltInRendering is on and BuiltInCustomRenderedTargetElement is BuiltInCustomRenderedTargetElement.Row or BuiltInCustomRenderedTargetElement.All. It is a gradient from GlassBrushTopHalfStartColor to GlassBrushBottomHalfEndColor, in the direction of OrientationAspectForRenderingRow. It is not drawn on selected rows or during a drag.

See also

DrawNodeConnectingLines

public bool DrawNodeConnectingLines

Gets or sets whether lines are drawn joining each node to its parent and its siblings.

Value
true by default.
Default
true
See also

EnableAutomaticBuiltInDragDrop

public bool EnableAutomaticBuiltInDragDrop

Gets or sets whether the user can rearrange the tree by dragging nodes with the mouse.

Value
false by default. Setting it also sets Control.AllowDrop to the same value.
Remarks

With it on, the user presses on a node and drags; the row under the pointer is highlighted in RowSelectionBackColorDuringDragOver and RowSelectionForeColorDuringDragOver, with a line beneath it. Dropping on a node makes the dragged node, and everything beneath it, the last child of that node; dropping on the empty area below the last row makes it the last top-level node. A drop on the node itself or on one of its own descendants does nothing, and Escape cancels the drag.

The branch is moved as a copy: new BinaryTreeListViewNode objects with the same cell values, check state and glyph images replace the old ones, and arrive closed. Look the nodes up again after a drop rather than keeping references to them.

For drag and drop of your own, leave this off, set Control.AllowDrop, and handle ItemDrag.

Example
// Let the user reorganise the plan by dragging tasks under other tasks.
plan.EnableAutomaticBuiltInDragDrop = true;
plan.ExpandTargetDropNodeUponDragDrop = true;
plan.RowSelectionBackColorDuringDragOver = Color.FromArgb(204, 228, 247);
plan.RowSelectionForeColorDuringDragOver = Color.Black;
See also

EnableCommitingEditWhenMovingFocusFromEditContext

public bool EnableCommitingEditWhenMovingFocusFromEditContext

Gets or sets whether an edit in progress is committed when the user clicks the glyph, check box or image area of a tree cell.

Value
true by default.
Remarks

With it on, a click on the left-hand part of a tree cell – the indent, the expand glyph, the check box or the image – ends the current edit and keeps the new value before acting on the click. With it off, the edit stays open.

EnableExpandCollapsingOfNodesUponMouseClickOnReadOnlyTreeListViewNodeCellOrColumn

public bool EnableExpandCollapsingOfNodesUponMouseClickOnReadOnlyTreeListViewNodeCellOrColumn

Gets or sets whether, in a read-only tree, a click anywhere in a node's tree cell opens or closes the node.

Value
true by default.
Remarks

It applies when the grid is read-only, or the current cell, its row or its column is. A click on the tree cell of a node that has children then toggles it, wherever in the cell the click lands, and the click goes no further – a check box in that cell does not change.

When nothing is read-only, or this is off, only a click on the expand glyph toggles a node (and a double-click, see ExpandCollapseNodeOnDoubleClick).

EndColorForRenderingColumnHeader

public Color EndColorForRenderingColumnHeader

Gets or sets the colour at the bottom or right of the gradient the built-in renderer fills the column headings with.

Value
SystemColors.Control by default.
Remarks

The gradient runs from StartColorForRenderingColumnHeader to EndColorForRenderingColumnHeader in the direction OrientationAspectForRenderingColumnHeader gives; set both to the same colour for a flat fill. It is painted while UseBuiltInRendering is on and BuiltInCustomRenderedTargetElement includes the column headings. Changing it does not repaint the control; call Control.Invalidate to see the change at once.

EndColorForRenderingRow

public Color EndColorForRenderingRow

Gets or sets the colour at the bottom or right of the gradient the built-in renderer fills each cell of the rows with.

Value
SystemColors.Window by default.
Remarks

The gradient runs from StartColorForRenderingRow to EndColorForRenderingRow in the direction OrientationAspectForRenderingRow gives; set both to the same colour for a flat fill. It is painted while UseBuiltInRendering is on and BuiltInCustomRenderedTargetElement includes the rows. Changing it does not repaint the control; call Control.Invalidate to see the change at once.

EndColorForRenderingRowHeader

public Color EndColorForRenderingRowHeader

Gets or sets the colour at the bottom or right of the gradient the built-in renderer fills the row headings with.

Value
SystemColors.Control by default.
Remarks

The gradient runs from StartColorForRenderingRowHeader to EndColorForRenderingRowHeader in the direction OrientationAspectForRenderingRowHeader gives; set both to the same colour for a flat fill. It is painted while UseBuiltInRendering is on and BuiltInCustomRenderedTargetElement includes the row headings. Changing it does not repaint the control; call Control.Invalidate to see the change at once.

ExpandCollapseNodeOnDoubleClick

public bool ExpandCollapseNodeOnDoubleClick

Gets or sets whether double-clicking a node's cell in the tree column opens or closes the node.

Value
true by default.
Default
true
Remarks

Only nodes with children respond, and not while the cell is being edited. A click on the expand glyph toggles a node whatever this is set to.

ExpandCollapsingOfNodesLevel

public ExpandCollapsingOfNodesLevel ExpandCollapsingOfNodesLevel

Gets or sets where the focus must be for Shift+Right and Shift+Left to open and close a node.

Value
ExpandCollapsingOfNodesLevel.Row by default.
Remarks

Shift+Right opens a closed node that has children; Shift+Left closes an open one.

ExpandImage

public Image ExpandImage

Gets or sets the image drawn as the expand glyph of a closed node that has children.

Value
null, the default, for the system tree glyph.
Remarks

Takes effect only when CollapseImage is set as well; with either one missing, the system glyph is used for both. The image is drawn 10 by 10 logical pixels. A node's own BinaryTreeListViewNode.ExpandImage takes precedence.

Example
plan.ExpandImage = Properties.Resources.ChevronRight;    // shown on a closed node
plan.CollapseImage = Properties.Resources.ChevronDown;   // shown on an open node
See also

ExpandTargetDropNodeUponDragDrop

public bool ExpandTargetDropNodeUponDragDrop

Gets or sets whether the node a dragged node is dropped on is opened, with everything beneath it, so that the moved node can be seen in its new place.

Value
false by default. A node dropped on a closed node is then out of sight until that node is opened.
See also

FrameBorderColor

public Color FrameBorderColor

Gets or sets the colour of the frame's border.

Value
A cool grey, RGB 196, 204, 216, by default.
Default
196, 204, 216
Remarks

Used while ShouldDrawFrame is on, and replaced by FrameFocusedBorderColor while the focus is in the control. Setting it repaints the frame at once.

See also

FrameBorderThickness

public int FrameBorderThickness

Gets or sets the thickness of the frame's border.

Value
In logical pixels, from 0 to 8; 1 by default. A value outside that range is clamped to it, and 0 draws no border line.
Default
1
See also

FrameCornerRadius

public int FrameCornerRadius

Gets or sets the radius of the frame's rounded corners.

Value
In logical pixels, from 0 to 32; 6 by default. A value outside that range is clamped to it, and 0 gives square corners.
Default
6
Remarks

The radius is never drawn larger than half the frame's shorter side. A larger radius also needs more padding to keep the square grid inside the curve; see FramePadding.

See also

FrameFocusedBorderColor

public Color FrameFocusedBorderColor

Gets or sets the colour of the frame's border while the focus is in the control – on the grid or on a cell's editor.

Value
Color.Empty, the default, to keep FrameBorderColor whether or not the control has the focus.
Default
Remarks

An accent colour here shows the user which grid the keyboard is in, as a focused text box does.

See also

FramePadding

public int FramePadding

Gets or sets the space between the frame's border and the grid inside it.

Value
In logical pixels, from 0 to 16; 3 by default. A value outside that range is clamped to it.
Default
3
Remarks

The padding used is never less than three tenths of FrameCornerRadius, which is what keeps the grid's square corners inside the rounded ones. It is filled with DataGridView.BackgroundColor.

See also

FrameShadowColor

public Color FrameShadowColor

Gets or sets the colour of the frame's drop shadow.

Value
Color.Black by default.
Default
Black
Remarks

The shadow's strength is FrameShadowOpacity, so the colour's own alpha is not used.

See also

FrameShadowDepth

public int FrameShadowDepth

Gets or sets how far the frame's shadow spreads.

Value
In logical pixels, from 0 to 24; 6 by default. A value outside that range is clamped to it, and 0 draws no shadow.
Default
6
Remarks

A third of the depth is also the distance the shadow drops below the frame, so it is deeper at the bottom than at the top.

See also

FrameShadowOpacity

public int FrameShadowOpacity

Gets or sets the strength of the frame's shadow where it is darkest, next to the border.

Value
A percentage, from 0 to 100; 16 by default. A value outside that range is clamped to it, and 0 draws no shadow.
Default
16
See also

GlassBrushBottomHalfEndColor

public Color GlassBrushBottomHalfEndColor

Gets or sets the colour the hover highlight ends with – at the bottom of the row, or at its right when OrientationAspectForRenderingRow is horizontal.

Value
Color.LightSalmon by default. A colour with no opacity, such as Color.Empty, is replaced by the row's own colour washed a little towards the system highlight colour.
Example
// A pale blue hover band over plain rows.
plan.BuiltInCustomRenderedTargetElement = BuiltInCustomRenderedTargetElement.All;
plan.GlassBrushTopHalfStartColor = Color.FromArgb(235, 243, 252);
plan.GlassBrushBottomHalfEndColor = Color.FromArgb(214, 230, 248);
See also

GlassBrushBottomHalfStartColor

public Color GlassBrushBottomHalfStartColor

Gets or sets a colour kept for compatibility; the hover highlight does not use it.

Value
Color.White by default.
Remarks

The highlight is a two-colour gradient from GlassBrushTopHalfStartColor to GlassBrushBottomHalfEndColor.

GlassBrushLinearGradientFactor

public float GlassBrushLinearGradientFactor

Gets or sets a value kept for compatibility; the hover highlight does not use it.

Value
90 by default.
Remarks

The direction of the highlight's gradient follows OrientationAspectForRenderingRow.

GlassBrushTopHalfEndColor

public Color GlassBrushTopHalfEndColor

Gets or sets a colour kept for compatibility; the hover highlight does not use it.

Value
Color.White by default.
Remarks

The highlight is a two-colour gradient from GlassBrushTopHalfStartColor to GlassBrushBottomHalfEndColor.

GlassBrushTopHalfStartColor

public Color GlassBrushTopHalfStartColor

Gets or sets the colour the hover highlight starts with – at the top of the row, or at its left when OrientationAspectForRenderingRow is horizontal.

Value
Color.LightSalmon by default. A colour with no opacity, such as Color.Empty, is replaced by the row's own colour washed a little towards the system highlight colour.
See also

HierarchicalDataSource

public object HierarchicalDataSource

Gets or sets a table to build the whole tree from, in place of adding nodes in code.

Value
A DataTable or DataView; null by default.
Exceptions
System.Exception
The value is not a DataTable, a DataView or null; or DataGridView.DataSource is set.
Remarks

The table's shape

The first three columns are for the control, and must be named UID, ID and ParentID; the columns after them are the data, matched to the control's columns in order – the table's fourth column fills the control's first column, and so on. Add the control's columns first, at least as many as there are data columns.

ColumnMeaning

UID

The row's identity, unique across the whole table.

ID

Not used to build the tree, but the column must exist.

ParentID

The UID of the parent row, or -1 for a top-level row.

Values are compared and shown as text: every cell value becomes a string, so a column of numbers sorts as text unless you handle DataGridView.SortCompare.

Binding

Setting the property removes every node and builds the tree again, showing a busy message (BusyIndicatorText) while it works; the nodes start closed. Later changes to the table are not followed – set the property again to show them. Setting it to null removes every node. With ControlDataDisplayMode set to ControlDataDisplayMode.ListView the property is ignored; bind the grid's own DataGridView.DataSource instead.

Rows are placed in passes, in table order unless ShouldEnableLinkedRelationshipsTuning is on: each pass adds the top-level rows and every row whose parent is already in the tree. List parents before their children and one pass places everything; otherwise up to DepthForPreparingNodesWithChildren passes are made. In pass n (counting from 0), a row not yet placed whose ParentID is n - 1 is added as a top-level row, so a table that lists children before parents should not use small numbers such as 0 and 1 as UIDs of parent rows.

Example

An organisation chart from a table. Each person's ParentID is their manager's UID.

DataTable staff = new DataTable("Staff");
staff.Columns.Add("UID", typeof(int));
staff.Columns.Add("ID", typeof(int));
staff.Columns.Add("ParentID", typeof(int));
staff.Columns.Add("Name", typeof(string));
staff.Columns.Add("Role", typeof(string));
staff.Columns.Add("Location", typeof(string));

staff.Rows.Add(1, 1, -1, "Helen Ward",   "Chief Executive",      "London");
staff.Rows.Add(2, 1,  1, "Marcus Bell",  "Finance Director",     "London");
staff.Rows.Add(3, 2,  1, "Aisha Khan",   "Engineering Director", "Manchester");
staff.Rows.Add(4, 1,  3, "Owen Price",   "Platform Lead",        "Manchester");
staff.Rows.Add(5, 2,  3, "Lena Fischer", "Mobile Lead",          "Berlin");

org.Columns.Add(new BinaryTreeListViewColumn { HeaderText = "Name" });
org.Columns.Add(new DataGridViewTextBoxColumn { HeaderText = "Role" });
org.Columns.Add(new DataGridViewTextBoxColumn { HeaderText = "Location" });

org.HierarchicalDataSource = staff;
org.ExpandAllNodes();
See also

HighlightOnlyTreeListCellDuringDragOver

public bool HighlightOnlyTreeListCellDuringDragOver

Gets or sets whether only one cell, rather than the whole row, is coloured to show where a dragged node would be dropped.

Value
false by default, to colour the whole row.
Remarks

With it on, only the row's first cell is coloured – the tree cell when the tree column is the first column.

See also

IsChildDropDownShowing

public bool IsChildDropDownShowing

Gets whether a date cell is being edited and its drop-down calendar is open.

Value
true while the current cell is in a BinaryTreeListViewDatePickerColumn, is being edited, and its calendar is showing; otherwise false.
Remarks

Useful in a key or focus handler of your own, to leave the keys to the calendar while it is open.

LineDrawingColor

public Color LineDrawingColor

Gets or sets the colour of the lines that join the nodes.

Value
SystemColors.WindowText by default. The lines are one pixel wide.
Remarks

A colour between the text and the background – Color.Silver on a white grid, for instance – keeps the lines from competing with the data.

See also

LineDrawingDashStyle

public System.Drawing.Drawing2D.DashStyle LineDrawingDashStyle

Gets or sets the pattern of the lines that join the nodes: solid, dotted, dashed and so on.

Value
Solid by default. Dot gives the look of the Windows tree view.
See also

NodeImage

public Image NodeImage

Gets or sets the image shown beside every node's text, between the expand glyph and the text.

Value
null, the default, for no shared image.
Remarks

A node shows the image set on it through BinaryTreeListViewNode.Image if it has one, and this image otherwise. Setting this property also sets the BinaryTreeListViewNode.Image of each top-level node there is at that moment, replacing theirs – so set it before giving top-level nodes images of their own.

The image is drawn at its own pixel size, not scaled; a 16 by 16 image suits the default row height, which is not changed to fit a larger one. A node with a check box or radio button shows that instead.

Example
accounts.NodeImage = Properties.Resources.Ledger16;            // every account
accounts.Nodes[0].Image = Properties.Resources.Bank16;          // except the bank accounts
See also

Nodes

public BinaryTreeListViewNodesCollection Nodes

Gets the top-level nodes. This is where the tree is built.

Value
The collection of top-level nodes. It is never null.
Remarks

Add the columns first. BinaryTreeListViewNodesCollection.Add() takes one value per column, in column order, creates the node and returns it; add its children to its own BinaryTreeListViewNode.Nodes in the same way, to any depth. A top-level node is on show as soon as it is added; a child is on show once its parent is open.

Pass a value that is not null for the tree column on every node; Add can throw a NullReferenceException otherwise.

Example
// Columns: Account (the tree column), Code, Balance.
BinaryTreeListViewNode assets = ledger.Nodes.Add("Assets", "1000", 182500.00m);
BinaryTreeListViewNode bank = assets.Nodes.Add("Bank", "1100", 42750.00m);
bank.Nodes.Add("Current account", "1110", 39250.00m);
bank.Nodes.Add("Savings account", "1120", 3500.00m);
assets.Nodes.Add("Equipment", "1500", 139750.00m);
assets.Expand();
See also

NodesSortColumn

public DataGridViewColumn NodesSortColumn

Gets the column the tree is sorted by.

Value
The sorted column, or null when the nodes are in the order they were built in.
See also

NodesSortDirection

public SortOrder NodesSortDirection

Gets the direction the tree is sorted in.

Value
SortOrder.Ascending or SortOrder.Descending while sorted by NodesSortColumn; SortOrder.None, the default, when it is not sorted.

NodesSortOrder

public NodeSortOrder NodesSortOrder

Gets or sets the order of sibling rows in a tree built from HierarchicalDataSource with ShouldEnableLinkedRelationshipsTuning on: ascending or descending by UID.

Value
NodeSortOrder.Ascending by default.
Remarks

NodeSortOrder.Descending orders by descending UID; any other value by ascending UID. Without ShouldEnableLinkedRelationshipsTuning, rows keep the table's order and this has no effect.

Setting it binds the data again when the control has columns and a HierarchicalDataSource. Nodes added in code keep the order they were added in; to sort by a column's values, see SortNodesByColumn.

OptimiseLayoutRenderingDuringDragDrop

public bool OptimiseLayoutRenderingDuringDragDrop

Gets or sets whether layout is suspended while a dropped branch is moved, so that a large branch moves without the grid laying itself out for every row.

Value
false by default.
See also

OrientationAspectForRenderingColumnHeader

public LinearGradientMode OrientationAspectForRenderingColumnHeader

Gets or sets the direction of the gradient the built-in renderer fills the column headings with.

Value
Vertical, top to bottom, by default.
Remarks

Changing it does not repaint the control; call Control.Invalidate to see the change at once.

See also

OrientationAspectForRenderingRow

public LinearGradientMode OrientationAspectForRenderingRow

Gets or sets the direction of the gradient the built-in renderer fills each cell of a row with, and of the hover highlight.

Value
Vertical, top to bottom, by default.
Remarks

Each cell is filled on its own, so a horizontal gradient repeats in every cell. Changing it does not repaint the control; call Control.Invalidate to see the change at once.

See also

OrientationAspectForRenderingRowHeader

public LinearGradientMode OrientationAspectForRenderingRowHeader

Gets or sets the direction of the gradient the built-in renderer fills the row headings with.

Value
Horizontal, left to right, by default.
Remarks

Changing it does not repaint the control; call Control.Invalidate to see the change at once.

See also

RowSelectionBackColorDuringDragOver

public Color RowSelectionBackColorDuringDragOver

Gets or sets the background colour of the row a dragged node is over – the node it would be dropped on.

Value
Color.LightSalmon by default.
Remarks

Applies to the built-in drag and drop (EnableAutomaticBuiltInDragDrop). See HighlightOnlyTreeListCellDuringDragOver for whether the whole row or one cell is coloured.

RowSelectionForeColorDuringDragOver

public Color RowSelectionForeColorDuringDragOver

Gets or sets the text colour of the row a dragged node is over.

Value
Color.Black by default.
See also

RowTemplate

public new DataGridViewRow RowTemplate

Gets or sets the row the grid copies for new rows.

Value
A BinaryTreeListViewNode, set by the constructor. Its height is raised to fit the control's font when the font is larger than the framework default.
Remarks

Change its Height or DefaultCellStyle to change every new node; replacing it with a row that is not a BinaryTreeListViewNode breaks the tree.

Rows

public new DataGridViewRowCollection Rows

Gets the grid's rows: the nodes that are on show, in display order.

Value
The base grid's row collection. Each row is a BinaryTreeListViewNode.
Remarks

Do not add or remove rows here; the control keeps this collection in step with Nodes as nodes are added and as they open and close. Rows inside a closed node are not in it.

See also

ShouldDrawCellBorderWhenSelected

public bool ShouldDrawCellBorderWhenSelected

Gets or sets whether the current cell is outlined with a border of its own while it is not being edited.

Value
false by default.
Remarks

The border is drawn in CellBorderColor, CellBorderWidth pixels wide, in place of the grid's dotted focus rectangle. With whole-row selection it marks the cell the keyboard is on – the one F2 edits.

Example
plan.ShouldDrawCellBorderWhenSelected = true;
plan.CellBorderColor = Color.SteelBlue;
plan.CellBorderWidth = 2;

ShouldDrawColumnBackgroundUponCellSelection

public bool ShouldDrawColumnBackgroundUponCellSelection

Gets or sets whether the column of the current cell is tinted in ColumnBackgroundOnCellSelectionColor.

Value
false by default.
Remarks

The tint follows the column of the current cell. In a tree, where a click selects the whole row, that is the column that was clicked – and, before anything has been clicked, the first column, since the grid makes the first cell current when it is filled. When both column tints apply to the same column, the hover tint wins.

See also

ShouldDrawColumnBackgroundUponMouseHovering

public bool ShouldDrawColumnBackgroundUponMouseHovering

Gets or sets whether the column under the pointer is tinted in ColumnBackgroundOnMouseHoverColor.

Value
false by default.
Remarks

The tint is set as the column's DataGridViewColumn.DefaultCellStyle back colour, and put back to ColumnBackgroundDefaultCellStyleBackColor as the pointer leaves. It is hidden while the built-in renderer paints the rows, which fills the cells itself.

Example
// Help the eye follow a column down a wide plan.
plan.ColumnBackgroundOnMouseHoverColor = Color.FromArgb(246, 249, 253);
plan.ShouldDrawColumnBackgroundUponMouseHovering = true;
See also

ShouldDrawFrame

public bool ShouldDrawFrame

Gets or sets whether the control draws its own frame: a border with rounded corners, an inner padding and, optionally, a soft drop shadow, all inside its bounds.

Value
false by default.
Default
false
Remarks

The frame replaces DataGridView.BorderStyle: turning it on sets that to BorderStyle.None, and turning it off puts back what it was. It is painted in the control's non-client area, so the headings, the rows and the scroll bars all sit inside it and nothing is drawn over the data.

Outside the border – the shadow and the rounded corners – the control paints the background colour of the nearest parent that has an opaque one, so place it on a parent of a single colour. Inside the border, the padding is DataGridView.BackgroundColor.

The border turns FrameFocusedBorderColor while the focus is in the control. The other settings are FrameBorderColor, FrameBorderThickness, FrameCornerRadius, FramePadding, ShouldDrawFrameShadow, FrameShadowColor, FrameShadowDepth and FrameShadowOpacity.

Example
plan.ShouldDrawFrame = true;
plan.FrameCornerRadius = 8;
plan.FrameBorderColor = Color.FromArgb(200, 208, 220);
plan.FrameFocusedBorderColor = Color.FromArgb(0, 120, 212);
plan.FrameShadowDepth = 8;
plan.FrameShadowOpacity = 12;
plan.BackgroundColor = Color.White;      // the padding inside the border

ShouldDrawFrameShadow

public bool ShouldDrawFrameShadow

Gets or sets whether the frame casts a soft drop shadow.

Value
true by default.
Default
true
Remarks

The shadow is drawn inside the control's bounds, so it takes room from the grid on every side, about FrameShadowDepth logical pixels.

See also

ShouldEnableFastCaching

public bool ShouldEnableFastCaching

Gets or sets whether binding makes a single pass over the data, rather than DepthForPreparingNodesWithChildren passes.

Value
false by default.
Remarks

One pass places every row whose parent row comes before it, so it is all a table needs when parents are listed before their children (or, with ShouldEnableLinkedRelationshipsTuning, have smaller UIDs). A row the single pass cannot place is left out. It applies the next time the data is bound.

See also

ShouldEnableLinkedRelationshipsTuning

public bool ShouldEnableLinkedRelationshipsTuning

Gets or sets whether rows from HierarchicalDataSource are placed in the order of their UID rather than the order of the table.

Value
false by default.
Remarks

With it on, every UID must be a whole number (a FormatException is thrown otherwise); rows are taken in ascending UID order – descending when NodesSortOrder is NodeSortOrder.Descending – so siblings appear in that order, and a row whose UID repeats an earlier one is left out. When every parent has a smaller UID than its children, the whole tree is built in one pass whatever the order of the table.

It applies the next time the data is bound.

See also

ShowNodeImage

public bool ShowNodeImage

Gets or sets whether the top-level nodes show their image.

Value
true by default.
Remarks

Setting it sets BinaryTreeListViewNode.ShowNodeImage on each top-level node there is at that moment, and repaints. Nested nodes, and nodes added afterwards, keep their own setting (true unless changed); set BinaryTreeListViewNode.ShowNodeImage on them to hide theirs.

See also

SpecialColumnCellsToDisplayEditingControlOnCellsAlways

public bool SpecialColumnCellsToDisplayEditingControlOnCellsAlways

Gets or sets whether cells of the special editing columns show their editor's chrome on every row, not only on the cell being edited.

Value
true by default.
Remarks

With it on, a BinaryTreeListViewDatePickerColumn cell draws its drop-down button, a BinaryTreeListViewNumericUpDownColumn cell its up and down buttons, and a BinaryTreeListViewOffice2007ColorPickerColumn cell its border and drop-down button, so the user can see at a glance which cells are editable and how. Each of those columns' DrawStyleIsFlat chooses between a flat chevron and the classic themed button.

With it off, those cells look like plain text cells until they are edited. A colour cell still shows its swatch. The setting is read as the cells paint; call Control.Invalidate after changing it to see the change at once.

StartColorForRenderingColumnHeader

public Color StartColorForRenderingColumnHeader

Gets or sets the colour at the top or left of the gradient the built-in renderer fills the column headings with.

Value
SystemColors.Control by default.
Remarks

The gradient runs from StartColorForRenderingColumnHeader to EndColorForRenderingColumnHeader in the direction OrientationAspectForRenderingColumnHeader gives; set both to the same colour for a flat fill. It is painted while UseBuiltInRendering is on and BuiltInCustomRenderedTargetElement includes the column headings. Changing it does not repaint the control; call Control.Invalidate to see the change at once.

StartColorForRenderingRow

public Color StartColorForRenderingRow

Gets or sets the colour at the top or left of the gradient the built-in renderer fills each cell of the rows with.

Value
SystemColors.Window by default.
Remarks

The gradient runs from StartColorForRenderingRow to EndColorForRenderingRow in the direction OrientationAspectForRenderingRow gives; set both to the same colour for a flat fill. It is painted while UseBuiltInRendering is on and BuiltInCustomRenderedTargetElement includes the rows. Changing it does not repaint the control; call Control.Invalidate to see the change at once.

StartColorForRenderingRowHeader

public Color StartColorForRenderingRowHeader

Gets or sets the colour at the top or left of the gradient the built-in renderer fills the row headings with.

Value
SystemColors.Control by default.
Remarks

The gradient runs from StartColorForRenderingRowHeader to EndColorForRenderingRowHeader in the direction OrientationAspectForRenderingRowHeader gives; set both to the same colour for a flat fill. It is painted while UseBuiltInRendering is on and BuiltInCustomRenderedTargetElement includes the row headings. Changing it does not repaint the control; call Control.Invalidate to see the change at once.

UseBuiltInRendering

public bool UseBuiltInRendering

Gets or sets whether the control paints the parts named by BuiltInCustomRenderedTargetElement itself, in gradients of the colours you choose, instead of leaving them to the grid.

Value
true by default. With the default colours the headings are painted in a flat SystemColors.Control.
Remarks

Each part is filled with a linear gradient from its start colour to its end colour, in the direction its orientation property gives, and its text and selection are then drawn over it:

PartColours and direction

Column headings

StartColorForRenderingColumnHeader, EndColorForRenderingColumnHeader, OrientationAspectForRenderingColumnHeader; also ColumnHeaderBottomBorderColor and DrawColumnSeparatorWhenUsingBuiltinRendering.

Row headings

StartColorForRenderingRowHeader, EndColorForRenderingRowHeader, OrientationAspectForRenderingRowHeader.

Rows

StartColorForRenderingRow, EndColorForRenderingRow, OrientationAspectForRenderingRow; also CellBorderDrawingColor and the hover highlight (DrawGlassBackgroundHighlightingOnMouseEnter).

Changing it does not repaint the control; call Control.Invalidate to see the change at once.

Example
// Headings in a soft blue gradient with a rule beneath them; rows left to the grid.
plan.UseBuiltInRendering = true;
plan.BuiltInCustomRenderedTargetElement = BuiltInCustomRenderedTargetElement.ColumnHeader;
plan.StartColorForRenderingColumnHeader = Color.FromArgb(244, 248, 252);
plan.EndColorForRenderingColumnHeader = Color.FromArgb(222, 232, 244);
plan.ColumnHeaderBottomBorderColor = Color.FromArgb(160, 180, 205);
plan.Invalidate();
See also

VirtualMode

public new bool VirtualMode

Gets or sets whether the grid asks for cell values as it needs them rather than holding them.

Value
false by default.
Remarks

The same as VirtualMode, except that setting it repaints the control. Nodes hold their own values, so a tree has no use for it.

Methods

About

public void About()

Shows the control's About box as a modal dialog.

Remarks

It backs the About entry on the control's design-time menu; an application has no need to call it.

BindToTreeListView

public void BindToTreeListView(object dataSource, int depth)

Builds the tree from a table now, without setting HierarchicalDataSource.

Parameters
dataSource
A DataTable or DataView shaped as HierarchicalDataSource describes.
depth
The number of passes to make over the rows (see DepthForPreparingNodesWithChildren); 0 or less only clears the tree. With ShouldEnableFastCaching on, one pass is made whatever this is.
Exceptions
System.Exception
dataSource is not a DataTable or DataView, or has no columns, and depth is at least 1.
Remarks

Every node is removed first. No busy message is shown, and HierarchicalDataSource is left as it was, so a later change to NodesSortOrder or DepthForPreparingNodesWithChildren does not rebind this table.

See also

ClearAllNodes

public void ClearAllNodes()

Removes every node, at every level, and every row from the control.

Remarks

The columns stay. Use this rather than Nodes.Clear(), which leaves the rows on show.

See also

CollapseAllNodes

public void CollapseAllNodes()

Closes every node in the tree, at every level, leaving only the top-level nodes on show.

Remarks

Nested nodes are closed too, so opening a top-level node afterwards shows its children closed. BinaryTreeListViewNodeCollapsing and BinaryTreeListViewNodeCollapsed are raised for each node that was open.

See also

CollapseNode

public bool CollapseNode(BinaryTreeListViewNode startNodeToCollapse, bool performDeepCollapse)

Closes a node and, if asked, every node beneath it.

Parameters
startNodeToCollapse
The node to close. It must be in this control.
performDeepCollapse
true to close every descendant as well, so that the branch reopens one level at a time; false to close only startNodeToCollapse, leaving its children as they were for when it reopens.
Returns

Always true.

Remarks
See also

CollapseNode

public bool CollapseNode(BinaryTreeListViewNode binaryTreeListViewNode)

Closes a node, taking its descendants off the grid.

Parameters
binaryTreeListViewNode
The node to close. It must be in this control.
Returns

true when the node was closed; false when it was already closed or a BinaryTreeListViewNodeCollapsing handler cancelled it.

Remarks

Raises BinaryTreeListViewNodeCollapsing and then BinaryTreeListViewNodeCollapsed. Children keep their own open state for when the node is opened again; to close them as well, use CollapseNode().

See also

Dispose

protected override void Dispose(bool disposing)

Releases the nodes' rows and the control's other resources.

Parameters
disposing
true when called from Dispose; false when called from the finalizer.

ExpandAllNodes

public void ExpandAllNodes()

Opens every node in the tree, at every level.

Remarks

Each node is opened through BinaryTreeListViewNode.Expand(), so BinaryTreeListViewNodeExpanding and BinaryTreeListViewNodeExpanded are raised for each one. A node whose opening a handler cancels stays closed.

Example
expandAllButton.Click += (sender, e) => accounts.ExpandAllNodes();
collapseAllButton.Click += (sender, e) => accounts.CollapseAllNodes();
See also

ExpandNode

public bool ExpandNode(BinaryTreeListViewNode startNodeToExpand, bool performDeepExpansion)

Opens a node and, if asked, every node beneath it.

Parameters
startNodeToExpand
The node to open. It must be in this control.
performDeepExpansion
true to open every descendant as well, from the top down; false to open only startNodeToExpand.
Returns

Always true.

Remarks

Each node is opened as ExpandNode() opens it, raising BinaryTreeListViewNodeExpanding and BinaryTreeListViewNodeExpanded; a node a handler keeps closed stays closed, and the return value does not report it.

Example
// Open the whole branch the user is on.
if (plan.CurrentNode != null)
    plan.ExpandNode(plan.CurrentNode, true);
See also

ExpandNode

public bool ExpandNode(BinaryTreeListViewNode binaryTreeListViewNode)

Opens a node, showing its children.

Parameters
binaryTreeListViewNode
The node to open. It must be in this control.
Returns

true when the node was opened; false when it was already open or a BinaryTreeListViewNodeExpanding handler cancelled it.

Remarks

Raises BinaryTreeListViewNodeExpanding and then BinaryTreeListViewNodeExpanded. Children that were themselves open before are shown open.

Open a node only when its parent is open, or when it is a top-level node: the children of a node whose parent is closed are placed at the top of the grid. To open a branch at any depth, use ExpandNode(), which works from the top down.

See also

GetAllSiblingsForThisNode

public IList<BinaryTreeListViewNode> GetAllSiblingsForThisNode(BinaryTreeListViewNode node, bool excludeThisNode)

Returns the nodes that share a parent with the given node.

Parameters
node
The node whose siblings are wanted. For a top-level node, the siblings are the other top-level nodes.
excludeThisNode
true to leave node itself out of the list; false to include it, in its place.
Returns

A new list, in the order the nodes appear under their parent. It is empty for a node that is not in a tree.

Exceptions
System.NullReferenceException
node is null.

GetFlatListOfNodes

public IEnumerable<BinaryTreeListViewNode> FlattenedNodes

Gets every node in the tree, at every level, as one flat sequence.

Value
A new list on each call, in tree order: each node followed by its descendants. Nodes inside closed branches are included.
Example
// Tasks not yet finished, at any depth, whether or not their branch is open.
int outstanding = plan.FlattenedNodes
    .Count(n => !n.HasChildren && ((WorkItem)n.Tag).PercentDone < 100);
See also

GetFlatListOfNodes

public IEnumerable<BinaryTreeListViewNode> GetFlatListOfNodes(BinaryTreeListViewNode startNodeWhoseChildrenCollectionAreNeededInTheList)

Returns every node beneath a node, at every level, as one flat sequence.

Parameters
startNodeWhoseChildrenCollectionAreNeededInTheList
The node whose descendants are wanted. It is not itself in the result.
Returns

A new list in tree order: each child followed by its own descendants. Nodes inside closed branches are included. It is empty for a node with no children.

Exceptions
System.NullReferenceException
startNodeWhoseChildrenCollectionAreNeededInTheList is null.
See also
  • FlattenedNodes

GetNodeAt

public BinaryTreeListViewNode GetNodeAt(Point clientPoint)

Returns the node shown at a point in the control.

Parameters
clientPoint
A point in the control's client coordinates, such as the location of a mouse event.
Returns

The node whose row is at that point, or null when the point is on the headings, below the last row, or outside the control.

Example
// Right-click a task to get its context menu.
plan.MouseUp += (sender, e) =>
{
    if (e.Button != MouseButtons.Right)
        return;

    BinaryTreeListViewNode node = plan.GetNodeAt(e.Location);
    if (node != null)
    {
        plan.CurrentCell = node.Cells[0];
        taskMenu.Show(plan, e.Location);
    }
};

OnCellMouseDoubleClick

protected override void OnCellMouseDoubleClick(DataGridViewCellMouseEventArgs e)

Raises the DataGridView.CellMouseDoubleClick event, then opens or closes the node when ExpandCollapseNodeOnDoubleClick is on and the cell is in the tree column.

Parameters
e
The data for the event.

OnCellMouseDown

protected override void OnCellMouseDown(DataGridViewCellMouseEventArgs e)

Raises the DataGridView.CellMouseDown event, noting where a pressed column heading stood, so that a heading dragged to a new place is not also taken as a click to sort.

Parameters
e
The data for the event.

OnCellMouseEnter

protected override void OnCellMouseEnter(DataGridViewCellEventArgs e)

Raises the DataGridView.CellMouseEnter event, and moves the hover highlight to the row the pointer has entered.

Parameters
e
The data for the event.

OnCellMouseLeave

protected override void OnCellMouseLeave(DataGridViewCellEventArgs e)

Raises the DataGridView.CellMouseLeave event, and clears the hover highlight from the row the pointer has left.

Parameters
e
The data for the event.

OnCellPainting

protected override void OnCellPainting(DataGridViewCellPaintingEventArgs e)

Raises the DataGridView.CellPainting event, then paints the parts the control draws itself: the built-in gradients and hover highlight, the sort glyph and the current cell's border.

Parameters
e
The data for the event.
Remarks

A DataGridView.CellPainting handler runs first. A cell it paints and marks handled is painted over by the built-in renderer when that renderer owns the cell.

OnColumnAdded

protected override void OnColumnAdded(DataGridViewColumnEventArgs e)

Raises the DataGridView.ColumnAdded event, after making the new column NotSortable so that sorting is the control's own (see AllowUserToSortColumns).

Parameters
e
The data for the event.
Exceptions
System.Exception
The column is a BinaryTreeListViewColumn and ControlDataDisplayMode is ControlDataDisplayMode.ListView.

OnColumnHeaderMouseClick

protected override void OnColumnHeaderMouseClick(DataGridViewCellMouseEventArgs e)

Raises the DataGridView.ColumnHeaderMouseClick event, after sorting by the column when AllowUserToSortColumns is on.

Parameters
e
The data for the event.
Remarks

The sort is done before the event is raised, so a handler sees the new order.

OnColumnWidthChanged

protected override void OnColumnWidthChanged(DataGridViewColumnEventArgs e)

Raises the DataGridView.ColumnWidthChanged event, then paints any part of the control waiting to be painted.

Parameters
e
The data for the event.

OnDataError

protected override void OnDataError(bool displayErrorDialogIfNoHandler, DataGridViewDataErrorEventArgs e)

Raises the DataGridView.DataError event when AllowDataErrorExceptionToBeThrown is on; otherwise ignores the error.

Parameters
displayErrorDialogIfNoHandler
true to show the grid's error dialog when nothing handles the event.
e
What went wrong, and on which cell.

OnFontChanged

protected override void OnFontChanged(EventArgs e)

Raises the FontChanged event, and resizes rows that still have their default height so that the new font fits them.

Parameters
e
The data for the event.

OnHandleCreated

protected override void OnHandleCreated(EventArgs e)

Raises the Control.HandleCreated event, and sizes rows that still have the default height to fit the control's font.

Parameters
e
The data for the event.

OnKeyDown

protected override void OnKeyDown(KeyEventArgs e)

Raises the Control.KeyDown event, and handles the control's own keys: Shift+Right and Shift+Left to open and close the current node, F2 to edit the current cell, and Enter to return to whole-row selection.

Parameters
e
The data for the event.
Remarks

The base grid's key handling runs twice for each key press, so a Control.KeyDown handler is called twice for the same key. A handler that sets KeyEventArgs.Handled stops the F2 and Enter handling.

See also

OnMouseDown

protected override void OnMouseDown(MouseEventArgs e)

Raises the Control.MouseDown event, notes the node under the pointer for ItemDrag, and restores CellEditingMode when the current cell is not in the tree column.

Parameters
e
The data for the event.

OnMouseLeave

protected override void OnMouseLeave(EventArgs e)

Raises the Control.MouseLeave event, and clears any hover highlight.

Parameters
e
The data for the event.
Remarks

The pointer can leave the control without leaving a cell first – across the border, or when the window loses the mouse – so the highlight is cleared here as well.

OnMouseMove

protected override void OnMouseMove(MouseEventArgs e)

Raises the Control.MouseMove event, and raises ItemDrag when a node is dragged far enough.

Parameters
e
The data for the event.

OnMouseUp

protected override void OnMouseUp(MouseEventArgs e)

Raises the Control.MouseUp event.

Parameters
e
The data for the event.

OnParentChanged

protected override void OnParentChanged(EventArgs e)

Raises the Control.ParentChanged event, and starts watching the new parent's size so that the scroll bars are laid out again when it changes.

Parameters
e
The data for the event.

OnRowEnter

protected override void OnRowEnter(DataGridViewCellEventArgs e)

Raises the DataGridView.RowEnter event, and returns the grid to whole-row selection, selecting the row entered.

Parameters
e
The data for the event.

OnRowsAdded

protected override void OnRowsAdded(DataGridViewRowsAddedEventArgs e)

Raises the DataGridView.RowsAdded event, after giving each node added its indent, and a height to suit the control's font.

Parameters
e
The data for the event.

OnSizeChanged

protected override void OnSizeChanged(EventArgs e)

Raises the Control.SizeChanged event.

Parameters
e
The data for the event.

SetUpNodeControlType

public void SetUpNodeControlType(NodeControlType controlType)

Gives every node now in the tree a check box, a radio button, or neither.

Parameters
controlType
NodeControlType.CheckBox to give every node a ticked check box, NodeControlType.RadioButton an unselected radio button, or NodeControlType.Default to remove them and show images again.
Remarks

It sets BinaryTreeListViewNode.CellInfoCheckStatus on every node at every level that exists when it is called; nodes added later start with none, so set theirs as you add them. Check boxes and radio buttons are drawn only on nodes without children, in place of the image, and the user changes them by clicking. The control is not repainted by this call – call Control.Invalidate if it is already on show.

Example
// A list of report sections to include, all ticked to begin with.
reports.SetUpNodeControlType(BinaryTreeListView.NodeControlType.CheckBox);
reports.Invalidate();

// Later: the sections still ticked.
List<string> chosen = reports.FlattenedNodes
    .Where(n => n.CellInfoCheckStatus == CellInfoCheckStatus.CheckBoxCheckedNormal)
    .Select(n => (string)n.Tag)
    .ToList();
See also

SortNodesByColumn

public void SortNodesByColumn(DataGridViewColumn column, SortOrder order)

Sorts the tree by the values in a column – siblings within their parent, at every level, closed branches included – or, with SortOrder.None, puts back the order the nodes were built in.

Parameters
column
A column of this control.
order
SortOrder.Ascending, SortOrder.Descending, or SortOrder.None for the original order.
Exceptions
System.ArgumentNullException
column is null.
System.ArgumentException
column belongs to another grid, or to none.
Remarks

Values of the same type that can be compared – numbers, dates, strings – compare as that type; anything else compares by its text in the current culture, ignoring case. Empty values sort first in ascending order. Nodes that compare equal keep their order. Handle DataGridView.SortCompare to decide a comparison yourself: the row indices it is given are -1 for a node that is not on show because its parent is closed.

An edit in progress is committed first, the current node stays current, and the scroll position is kept. Nodes added after a sort are not placed by it; sort again to include them. NodesSortColumn and NodesSortDirection report the result, and the column's heading shows the sort glyph.

Example
// Largest balances first, within each branch.
ledger.SortNodesByColumn(ledger.Columns["Balance"], SortOrder.Descending);

// Sort account codes as numbers, although the cells hold text.
ledger.SortCompare += (sender, e) =>
{
    if (e.Column.Name == "Code")
    {
        e.SortResult = int.Parse((string)e.CellValue1).CompareTo(int.Parse((string)e.CellValue2));
        e.Handled = true;
    }
};
See also

WndProc

protected override void WndProc(ref Message m)

Processes the Windows messages sent to the control's window, reserving and painting the frame when ShouldDrawFrame is on.

Parameters
m
The message.
Remarks

The frame's ring is taken off the window before the grid lays out its headings, rows and scroll bars in what is left, and is painted after the default non-client painting.

Events

BinaryTreeListViewCellClicked

public event BinaryTreeListViewCellClickedHandler BinaryTreeListViewCellClicked

Occurs when the user presses the mouse button on a cell of the tree column, before the control acts on the click.

Remarks

BinaryTreeListViewCellClickedEventArgs.BinaryTreeListViewCellClickedArea says which part of the cell was clicked: the expand glyph, the check box or radio button, the image, or the text. Set Cancel to stop what would follow – the node opening or closing, a check box changing, or the cell starting an edit.

The event comes before a check box changes, so BinaryTreeListViewNode.CellInfoCheckStatus still holds the old state in the handler. A radio button with no siblings changes before the event; one with siblings changes after it.

Example
// Open a document when its icon is clicked, and do nothing else with that click.
tree.BinaryTreeListViewCellClicked += (sender, e) =>
{
    if (e.BinaryTreeListViewCellClickedArea == BinaryTreeListViewCellClickedArea.Image)
    {
        OpenDocument((string)e.Node.Tag);
        e.Cancel = true;
    }
};
See also

BinaryTreeListViewNodeCollapsed

public event BinaryTreeListViewNodeCollapsedEventHandler BinaryTreeListViewNodeCollapsed

Occurs after a node has closed and the rows beneath it have been taken out of the grid.

Remarks

A node keeps its own open or closed state for each of its children, so a child that was open is open again when its parent reopens.

See also

BinaryTreeListViewNodeCollapsing

public event BinaryTreeListViewNodeCollapsingEventHandler BinaryTreeListViewNodeCollapsing

Occurs before an open node closes, whether the user closed it or code did; the closing can be cancelled.

Remarks

Set Cancel to keep the node open; the call that asked for it then returns false. It is not raised for a node that is already closed.

See also

BinaryTreeListViewNodeExpanded

public event BinaryTreeListViewNodeExpandedEventHandler BinaryTreeListViewNodeExpanded

Occurs after a node has opened and its children have been added to the grid.

Remarks

Raised once per node opened, so ExpandAllNodes raises it for every node that had to open. It is not raised when BinaryTreeListViewNodeExpanding was cancelled.

See also

BinaryTreeListViewNodeExpanding

public event BinaryTreeListViewNodeExpandingEventHandler BinaryTreeListViewNodeExpanding

Occurs before a node opens, whether the user opened it or code did; the opening can be cancelled.

Remarks

Set Cancel to keep the node closed; the call that asked for it then returns false. Children added to BinaryTreeListViewNodeExpandingEventArgs.Node inside the handler are shown as the node opens, which is the way to load a large tree only as it is explored.

It is raised for every expand request on a closed node, including one with no children.

Example

Loading a folder's contents the first time it is opened. Each folder is added with one placeholder child, so that it shows an expand glyph.

tree.BinaryTreeListViewNodeExpanding += (sender, e) =>
{
    BinaryTreeListViewNode folder = e.Node;
    if (folder.Nodes.Count != 1 || folder.Nodes[0].Tag != null)
        return;                                   // already loaded

    folder.Nodes.RemoveAt(0);                     // the placeholder
    foreach (string path in Directory.GetFileSystemEntries((string)folder.Tag))
    {
        BinaryTreeListViewNode child = folder.Nodes.Add(Path.GetFileName(path), File.GetLastWriteTime(path));
        child.Tag = path;
    }
};
See also

ItemDrag

public event ItemDragEventHandler ItemDrag

Occurs when the user starts dragging a node, for drag and drop you handle yourself.

Remarks

It is raised when Control.AllowDrop is on, EnableAutomaticBuiltInDragDrop is off, and the pointer moves beyond the system drag distance with the left button held down over a node. Item is the BinaryTreeListViewNode pressed on. Call Control.DoDragDrop from the handler to start the drag.

Example
accounts.AllowDrop = true;
accounts.ItemDrag += (sender, e) =>
{
    BinaryTreeListViewNode node = (BinaryTreeListViewNode)e.Item;
    accounts.DoDragDrop(node.Tag, DragDropEffects.Copy);   // hand the account object to another window
};
See also