# 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](https://www.telerik.com/maui-ui/documentation/knowledge-base/treeview-net-maui-load-children-checkbox-recursive) article.

Here is how the Independent `CheckBoxMode` looks:

![.NET MAUI TreeView Independent Mode](https://www.telerik.com/maui-ui/documentation/assets/32836871c30f52a0d559df8772824ff6/treeview-independent-mode.png)

Here is how the Recursive `CheckBoxMode` looks:

![.NET MAUI TreeView Recursive Mode](https://www.telerik.com/maui-ui/documentation/assets/12478f5a0434cda5d79827b205bc7e9c/treeview-recursive-mode.png)

> 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](https://www.telerik.com/maui-ui/documentation/assets/e4f9703a6f9f3af42d7d028de2e42d04/treeview-check-uncheck-items.gif)

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

![.NET MAUI TreeView Check and Uncheck](https://www.telerik.com/maui-ui/documentation/assets/ac14a04117bebb7fada160dd0553d8fc/treeview-check-uncheck-item.gif)

> For a runnable example demonstrating the TreeView Check and Uncheck feature, see the [SDKBrowser Demo Application](https://www.telerik.com/maui-ui/documentation/demos-and-sample-apps/sdkbrowser-app) and go to **TreeView > Commands category**.

## See Also

* [Expand and Collapse TreeView Items](https://www.telerik.com/maui-ui/documentation/controls/treeview/expand-collapse)
* [Styling the TreeView Item](https://www.telerik.com/maui-ui/documentation/controls/treeview/styling/item-style)
* [Scrolling options](https://www.telerik.com/maui-ui/documentation/controls/treeview/scrolling)
* [Multiple and Single Selection](https://www.telerik.com/maui-ui/documentation/controls/treeview/selection)
* [Events](https://www.telerik.com/maui-ui/documentation/controls/treeview/events)
* [Available Commands in .NET MAUI TreeView](https://www.telerik.com/maui-ui/documentation/controls/treeview/commands)
