windowsforms-120672-controls-and-libraries-tree-list-feature-center-focus-selection-and-navigation-node-checking-checkboxes-and-radio-buttons.md
To select nodes, use the node checking feature, which enables built-in check boxes or radio buttons for tree levels. In bound mode, you can sync node check states with a database field. This document explains this subject in detail.
Tip
To select nodes by highlighting them, use the Node Selection feature.
Show check boxes/radio buttons for all nodes
Set the TreeListOptionsView.CheckBoxStyle property to Check or Radio.
treeList1.OptionsView.CheckBoxStyle = DefaultNodeCheckBoxStyle.Check;
//or
treeList1.OptionsView.CheckBoxStyle = DefaultNodeCheckBoxStyle.Radio;
treeList1.OptionsView.CheckBoxStyle = DefaultNodeCheckBoxStyle.Check
'or
treeList1.OptionsView.CheckBoxStyle = DefaultNodeCheckBoxStyle.Radio
Tip
Radio buttons are mutually exclusive options. When you check a certain radio button, the TreeList automatically unchecks a previously checked radio button at the same hierarchy level.
The TreeListOptionsView.CheckBoxStyle property specifies default check box display mode for all TreeList nodes. You can override this setting for root nodes and any node’s children, as shown below.
Show check boxes/radio buttons only for root nodes
Set the TreeListOptionsView.RootCheckBoxStyle property to Check or Radio. Leave the TreeListOptionsView.CheckBoxStyle property set to Default.
treeList1.OptionsView.RootCheckBoxStyle = NodeCheckBoxStyle.Check;
treeList1.OptionsView.CheckBoxStyle = DefaultNodeCheckBoxStyle.Default;
//or
treeList1.OptionsView.RootCheckBoxStyle = NodeCheckBoxStyle.Radio;
treeList1.OptionsView.CheckBoxStyle = DefaultNodeCheckBoxStyle.Default;
treeList1.OptionsView.RootCheckBoxStyle = NodeCheckBoxStyle.Check
treeList1.OptionsView.CheckBoxStyle = DefaultNodeCheckBoxStyle.Default
'or
treeList1.OptionsView.RootCheckBoxStyle = NodeCheckBoxStyle.Radio
treeList1.OptionsView.CheckBoxStyle = DefaultNodeCheckBoxStyle.Default
Show check boxes/radio buttons for all nodes, except root nodes
Set TreeListOptionsView.CheckBoxStyle to Check / Radio , and set TreeListOptionsView.RootCheckBoxStyle to None.
treeList1.OptionsView.CheckBoxStyle = DefaultNodeCheckBoxStyle.Check;
treeList1.OptionsView.RootCheckBoxStyle = NodeCheckBoxStyle.None;
//or
treeList1.OptionsView.CheckBoxStyle = DefaultNodeCheckBoxStyle.Radio;
treeList1.OptionsView.RootCheckBoxStyle = NodeCheckBoxStyle.None;
treeList1.OptionsView.CheckBoxStyle = DefaultNodeCheckBoxStyle.Check
treeList1.OptionsView.RootCheckBoxStyle = NodeCheckBoxStyle.None
'or
treeList1.OptionsView.CheckBoxStyle = DefaultNodeCheckBoxStyle.Radio
treeList1.OptionsView.RootCheckBoxStyle = NodeCheckBoxStyle.None
Show/hide check boxes/radio buttons for a certain node’s children
Use a node’s TreeListNode.ChildrenCheckBoxStyle property. This property overrides the TreeListOptionsView.CheckBoxStyle setting for the specified node’s children.
treeList1.OptionsView.CheckBoxStyle = DefaultNodeCheckBoxStyle.Check;
treeList1.OptionsView.RootCheckBoxStyle = NodeCheckBoxStyle.None;
TreeListNode node1 = treeList1.FindNodeByFieldValue("DEPARTMENT", "Sales and Marketing");
node1.ChildrenCheckBoxStyle = DevExpress.XtraTreeList.NodeCheckBoxStyle.Radio;
treeList1.OptionsView.CheckBoxStyle = DefaultNodeCheckBoxStyle.Check
treeList1.OptionsView.RootCheckBoxStyle = NodeCheckBoxStyle.None
Dim node1 As TreeListNode = treeList1.FindNodeByFieldValue("DEPARTMENT", "Sales and Marketing")
node1.ChildrenCheckBoxStyle = DevExpress.XtraTreeList.NodeCheckBoxStyle.Radio
Note
It is not possible to simultaneously display radio buttons and check boxes at the same hierarchy level.
Related API
Regular check boxes allow an end-user to toggle between the Checked and Unchecked states. If you enable the TreeListOptionsBehavior.AllowIndeterminateCheckState property, then the TreeList nodes will support three check states (Unchecked, Indeterminate and Checked). Clicking a check box sequentially toggles between these states.
Related API
To retrieve all checked nodes, use the TreeList.GetAllCheckedNodes method.
The following code shows how to retrieve checked nodes using the TreeList.GetAllCheckedNodes method, and modify their values.
List<TreeListNode> list = treeList1.GetAllCheckedNodes();
foreach (TreeListNode node in list) {
decimal budget = Convert.ToDecimal(node["BUDGET"])*1.1m;
node["BUDGET"] = budget;
}
Dim list As List(Of TreeListNode) = treeList1.GetAllCheckedNodes()
For Each node As TreeListNode In list
Dim budget As Decimal = Convert.ToDecimal(node("BUDGET")) * 1.1D
node("BUDGET") = budget
Next
You can recursively retrieve nodes that match a certain condition (for instance, unchecked nodes or nodes with the indeterminate state) using a node iterator.
The following example shows how to use a node iterator to retrieve unchecked TreeList nodes.
using DevExpress.XtraTreeList.Nodes.Operations;
GetUncheckedNodesOperation op = new GetUncheckedNodesOperation();
treeList1.NodesIterator.DoOperation(op);
//Get the number of unchecked nodes:
int count = op.TargetNodes.Count;
//The operation class that collects unchecked nodes
class GetUncheckedNodesOperation : TreeListOperation {
public List<TreeListNode> TargetNodes = new List<TreeListNode>();
public GetUncheckedNodesOperation() : base() { }
public override void Execute(TreeListNode node) {
if (node.CheckState == CheckState.Unchecked)
TargetNodes.Add(node);
}
}
Imports DevExpress.XtraTreeList.Nodes.Operations
Imports DevExpress.XtraTreeList.Nodes
Dim op As GetUncheckedNodesOperation = New GetUncheckedNodesOperation()
treeList1.NodesIterator.DoOperation(op)
'Get the number of unchecked nodes:
Dim count As Integer = op.TargetNodes.Count
'The operation class that collects unchecked nodes
Friend Class GetUncheckedNodesOperation
Inherits TreeListOperation
Public TargetNodes As List(Of TreeListNode) = New List(Of TreeListNode)()
Public Sub New()
MyBase.New()
End Sub
Public Overrides Sub Execute(ByVal node As TreeListNode)
If node.CheckState = CheckState.Unchecked Then
TargetNodes.Add(node)
End If
End Sub
End Class
Use the following members to specify node check states in code.
Recursive Checking
To check/uncheck child nodes when an end-user toggles a parent node’s check state and vice versa, use the TreeListOptionsBehavior.AllowRecursiveNodeChecking property.
TreeListNode node1 = treeList1.FindNodeByFieldValue("DEPARTMENT", "Sales and Marketing");
if (node1 != null)
treeList1.SetNodeCheckState(node1, CheckState.Checked, false);
Dim node1 As TreeListNode = treeList1.FindNodeByFieldValue("DEPARTMENT", "Sales and Marketing")
If node1 IsNot Nothing Then
treeList1.SetNodeCheckState(node1, CheckState.Checked, False)
End If
Use the TreeList.CheckBoxFieldName property to sync node check states with a specific data source field.
If TreeList nodes only support the checked and unchecked states, the bound data source field should be of the Boolean type. If TreeList nodes use three check states, the data source field should be of the Nullable Boolean type.
Handle the TreeList.BeforeCheckNode and TreeList.AfterCheckNode events.
You can custom paint check boxes by handling the TreeList.CustomDrawNodeCheckBox event.
To print/export check boxes, enable the TreeListOptionsPrint.PrintCheckBoxes option.