Skip to content

Latest commit

 

History

History
79 lines (50 loc) · 5.86 KB

checkboxes.md

File metadata and controls

79 lines (50 loc) · 5.86 KB
title page_title description position slug
CheckBox Elements
.NET MAUI TreeView Documentation - CheckBox Elements
Discover the CheckBox elements in the TreeView for .NET MAUI control and learn how to use and configure them.
3
treeview-checkboxes

Checkbox Elements

The TreeView for .NET MAUI allows you to show checkbox elements and check specific items from its ItemsSource. The checked items are added to the CheckedItems property of the control. You can also control the visibility of the checkbox elements as well as their state propagation.

Checkbox State Propagation

You can control the state propagation by setting the CheckBoxMode property (enum of type Telerik.Maui.Controls.TreeView.TreeViewCheckBoxMode). The TreeViewCheckBoxMode enum consists of the following values:

  • None(default)—Specifies that no checkboxes are displayed in the control.
  • Independent—Specifies that the checkboxes are checked and unchecked independently. The checked state of the parent item is not propagated to its children.
  • Recursive—Specifies that the checkboxes are checked and unchecked recursively. The checked state of the parent item is propagated to its children.

Recursive CheckBox Mode and Load Children on Demand

Consider the following scenarios when using the TreeView Recursive CheckBoxMode in a combination with the LoadChildrenOnDemand feature:

  • When checking the checkbox element of the parent item without loading the children, this parent item is added to the CheckedItems collection (the children are not).
  • When loading the children of the parent node by pressing the expand icon, and the checkbox of the parent node is checked, all child data items must be manually added to the CheckedItems collection.

For a runnable example demonstrating the TreeView Recursive CheckBoxMode and Load Children on Demand scenario, see the [Handling TreeView Load Children on Demand with Recursive CheckBox Mode]({%slug treeview-net-maui-load-children-checkbox-recursive%}) article.

Here is how the Independent CheckBoxMode looks:

.NET MAUI TreeView Independent Mode

Here is how the Recursive CheckBoxMode looks:

.NET MAUI TreeView Recursive Mode

To display checkboxes in the TreeView item, set the CheckBoxMode to Independent or Recursive.

Checked Items Collection

The control exposes a CheckedItems collection (IList). The collection holds the items that are currently checked.

Programmatically Check or Uncheck Items

The TreeView exposes methods and commands that enable you to programmatically check or uncheck item/all items.

The available methods are:

  • Check(params object[] itemPath)—Checks the item in hierarchy with the specified path. The itemPath parameter specifies the path to an item in the hierarchy to expand. The path is a collection if unique identifiers of items. The first element of the path identifies an item at the root level. The second element of the path identifies a child of the root item etc. The Telerik.Maui.Controls.TreeView.TreeViewDescriptor.IdentityMemberPath property has to be used to specify the unique identifier at each level of the hierarchy.
  • UnCheck(params object[] itemPath)—Unchecks the item in hierarchy with the specified path. The itemPath parameter specifies the path to an item in the hierarchy to expand. The path is a collection if unique identifiers of items. The first element of the path identifies an item at the root level. The second element of the path identifies a child of the root item etc. The Telerik.Maui.Controls.TreeView.TreeViewDescriptor.IdentityMemberPath property has to be used to specify the unique identifier at each level of the hierarchy.
  • CheckAll()—Checks all items in the control.
  • UnCheckAll()—Unchecks all items in the control.

The available commands are:

  • CheckCommand—Gets a command to check a specific item in the control. The command accepts a parameter specifying the path to the item. The path is a collection if unique identifiers of items. The first element of the path identifies an item at the root level. The second element of the path identifies a child of the root item etc. The Telerik.Maui.Controls.TreeView.TreeViewDescriptor.IdentityMemberPath property has to be used to specify the unique identifier at each level of the hierarchy.
  • UncheckCommand—Gets a command to uncheck a specific item in the control. The command accepts a parameter specifying the path to the item. The path is a collection if unique identifiers of items. The first element of the path identifies an item at the root level. The second element of the path identifies a child of the root item etc. The Telerik.Maui.Controls.TreeView.TreeViewDescriptor.IdentityMemberPath property has to be used to specify the unique identifier at each level of the hierarchy.
  • CheckAllCommand—Gets a command to expand all items in the control.
  • UncheckAllCommand—Gets a command to collapse all items in the control.

Here is how the TreeView CheckAll/UncheckAll command execution looks:

.NET MAUI TreeView Check and Uncheck

Here is how the TreeView Check/Uncheck command execution looks:

.NET MAUI TreeView Check and Uncheck

For a runnable example demonstrating the TreeView Check and Uncheck feature, see the [SDKBrowser Demo Application]({%slug sdkbrowser-app%}) and go to TreeView > Commands category.

See Also

  • [Expand and Collapse TreeView Items]({%slug treeview-expand-collapse%})
  • [Styling the TreeView Item]({%slug treeview-item-style%})
  • [Scrolling options]({%slug treeview-scrolling%})
  • [Multiple and Single Selection]({%slug treeview-selection%})
  • [Events]({%slug treeview-events%})
  • [Available Commands in .NET MAUI TreeView]({%slug treeview-commands%})