The problem
Sooner or later most Windows Forms applications need to show data that is both hierarchical and tabular: a bill of materials with quantities and prices, a folder tree with sizes and dates, a task list with subtasks, owners and progress. The framework offers two controls, and each one covers half of it.
- The TreeView shows the hierarchy, but every node is a single label. There are no columns and no column headers.
- The DataGridView has columns, headers and cell editing, but its rows are flat. There are no levels and no expand/collapse buttons.
The usual workarounds are owner-drawing the TreeView, faking indentation in a DataGridView, or placing two controls side by side and keeping them scrolled in sync. All three are a lot of code to write and to maintain. SftTree/NET 3.0 is a tree control for Windows Forms with grid-like features, written entirely in C#, that does both in one control.
Feature comparison
| Feature | TreeView | DataGridView | SftTree/NET 3.0 |
|---|---|---|---|
| Hierarchy | Yes | No, flat rows | Yes, unlimited levels, single or multiple roots |
| Columns | No, one label per node | Yes | Yes, resizable and reorderable |
| Headers and footers | No | One header row | Multiple header rows and footer rows |
| Editing | The node label | Cells | Cells, in place, with standard Windows Forms controls |
| Check boxes | One per node | In a check box column | In any cell, along with radio buttons, buttons and drop-down buttons |
| Progress bars in cells | No | Custom cell painting | Yes |
| Item height | The same for every node | Per row | Automatic, each item as tall as its contents, with word-wrapped text |
| Cell merging | No | No | Yes, vertically and horizontally |
| Selection | One node | Rows, columns or cells | Items or individual cells |
| Row headers, splitter bar | No | Row headers | Both |
What the code looks like
If you know the TreeView, SftTree/NET will look familiar. A node becomes an item, and an item has one cell for each column. This fills a three-column tree with a parent item and a child:
sftTree1.Initializing = true;
sftTree1.Columns.Count = 3;
sftTree1.Headers[0, 0].Text = "Part";
sftTree1.Headers[0, 1].Text = "Quantity";
sftTree1.Headers[0, 2].Text = "Price";
ItemClass assembly = sftTree1.ItemCollection.Add(new string[] { "Front assembly", "1", "249.00" });
ItemClass part = assembly.Add(new string[] { "Bracket", "4", "3.50" });
part.Cells[0].Parts.Add(new CheckBoxPartClass(CheckBoxStateEnum.Checked));
sftTree1.Columns.MakeOptimal(0, false);
sftTree1.Initializing = false;
You can also skip the code: the control is placed from the Visual Studio toolbox, and its property pages let you design columns, items, headers and footers visually.
Modern Windows
SftTree/NET 3.0 runs in .NET Framework 4.7 (or later) and .NET 10 (or later) applications, with Visual Studio designer support in both. It follows the Windows dark mode setting automatically, scales with the DPI of the monitor showing it, honors the Windows contrast themes and has built-in UI Automation support for Narrator, NVDA, JAWS and other screen readers.
When the built-in controls are enough
If all you need is a simple tree of labels, the TreeView is fine, and it is free. The same goes for a flat table and the DataGridView. SftTree/NET earns its place when you need the hierarchy and the columns together, or cells that hold more than text.
Try it
The free trial includes the working control and the C# and VB.NET samples. Test it in your own forms before you buy. A license is royalty-free and includes one year of support and upgrades.
