Siticone Tree View
The SiticoneTreeView is an enhanced version of the standard Windows Forms TreeView control.
It introduces Tri-State Checkboxes (automatically checking/unchecking parent and child nodes) and a robust event system
that provides detailed information about node interactions, state changes, and bulk updates.
Behavior & Checkboxes
Core properties controlling the hierarchical checkbox logic and interaction.
| Property | Type | Description & Usage Example |
|---|---|---|
CheckBoxes |
bool | treeView.CheckBoxes = true; Enables or disables checkboxes next to each tree node. Must be true for Tri-State logic to work. |
EnableTriStateCheckboxes |
bool |
treeView.EnableTriStateCheckboxes = true;
Enables smart checking logic:
|
ItemHeight |
int | treeView.ItemHeight = 35; Sets the vertical spacing for each node, allowing for touch-friendly layouts. |
Indent |
int | treeView.Indent = 25; The horizontal indentation distance for child nodes. |
Public Methods
Helper methods for programmatic control over nodes.
// Programmatically checks a node and triggers the associated events.
// node: The target TreeNode.
// isChecked: True to check, False to uncheck.
// fireEvents: Whether to raise NodeStateChanged events (default: true).
siticoneTreeView1.SetNodeChecked(myNode, true, true);
// Retrieves detailed state information about a specific node.
// Returns a NodeStateChangeEventArgs object containing level, parent, children, etc.
var info = siticoneTreeView1.GetNodeInfo(selectedNode);
Console.WriteLine($"Node Level: {info.NodeLevel}, Child Count: {info.ChildCount}");
Events
The control provides a rich set of events that offer far more detail than standard TreeView events.
They use custom event arguments like NodeInteractionEventArgs and TreeStateChangeEventArgs.
| Event | Description |
|---|---|
NodeStateChanging |
Fired before a checkbox state changes. Can be cancelled.
Args: CurrentCheckedState, ProposedCheckedState, Cancel.
|
NodeStateChanged |
Fired after a single node's checkbox state has changed.
Args: OldCheckedState, NewCheckedState, ChangeSource (UserClick, Programmatic, Cascade).
|
TreeStateChanged |
Fired when a bulk update occurs (e.g., checking a parent cascades to 50 children).
Args: ChangedNodes (List), TotalNodesAffected, TriggerNode.
|
NodeInteraction |
A unified event for all user interactions (Click, DoubleClick, Expand, Collapse, Select).
Args: InteractionType, ClickLocation, MouseButton.
|
NodeTextClicked |
Fired specifically when the user clicks the text label of a node (excluding the checkbox area). |
CheckboxClicked |
Fired specifically when the user clicks the checkbox area of a node. |
Detailed Usage Examples
Example 1: Handling Tri-State Changes
Logs when a user checks a parent node, showing how many child nodes were affected by the cascade.
private void siticoneTreeView1_TreeStateChanged(object sender, TreeStateChangeEventArgs e)
{
if (e.ChangeType == TreeStateChangeType.CascadeDown)
{
Console.WriteLine($"User clicked parent node '{e.TriggerNode.Text}'.");
Console.WriteLine($"Total nodes updated: {e.TotalNodesAffected}");
Console.WriteLine($"Nodes checked: {e.CheckedNodesCount}");
Console.WriteLine($"Nodes unchecked: {e.UncheckedNodesCount}");
}
}
Example 2: Preventing Node Check
Uses the NodeStateChanging event to prevent users from unchecking specific "locked" nodes.
private void siticoneTreeView1_NodeStateChanging(object sender, NodeStateChangingEventArgs e)
{
// Check a custom tag or property
if (e.Node.Tag != null && e.Node.Tag.ToString() == "Locked")
{
// Prevent unchecking
if (!e.ProposedCheckedState)
{
e.Cancel = true;
MessageBox.Show("This node cannot be disabled.");
}
}
}
Example 3: Detailed Click Handling
Differentiates between clicking the text vs. clicking the checkbox.
private void siticoneTreeView1_NodeTextClicked(object sender, NodeInteractionEventArgs e)
{
// Triggered only when clicking the text label
Console.WriteLine($"Opening details for: {e.NodeText}");
OpenDetailsPanel(e.Node);
}
private void siticoneTreeView1_CheckboxClicked(object sender, NodeInteractionEventArgs e)
{
// Triggered only when clicking the checkbox
Console.WriteLine($"Toggling selection for: {e.NodeText}");
}
Example 4: Lazy Loading with Expansion Event
Uses the NodeExpandedDetailed event to load child nodes dynamically only when requested.
private void siticoneTreeView1_NodeExpandedDetailed(object sender, NodeInteractionEventArgs e)
{
// Check if node has a dummy child indicating it needs loading
if (e.Node.Nodes.Count == 1 && e.Node.Nodes[0].Text == "...")
{
e.Node.Nodes.Clear();
// Load actual data
var data = GetChildrenFor(e.Node.Tag);
foreach (var item in data)
{
var newNode = new TreeNode(item.Name);
newNode.Tag = item.Id;
e.Node.Nodes.Add(newNode);
}
}
Console.WriteLine($"Node '{e.NodeText}' expanded at {e.InteractionTime}");
}