# Blazor Treeview Overview

The <a href="https://www.telerik.com/blazor-ui/treeview" target="_blank">Blazor Treeview component</a> displays data in a traditional tree-like structure. The data itself can be flat or hierarchical. In addition to built-in navigation capabilities, you can navigate through the items and their children, define [templates](https://www.telerik.com/blazor-ui/documentation/components/treeview/templates) for the individual nodes, render text, checkboxes and icons, and respond to events.

## Creating Blazor TreeView

1. Use the `TelerikTreeView` tag.
2. Set the TreeView `Data` attribute to an `IEnumerable<T>`. The TreeView will automatically recognize property names like `Id`, `ParentId`, `Text` and a few others. Otherwise, [use bindings to configure custom property names](https://www.telerik.com/blazor-ui/documentation/components/treeview/data-binding/overview#treeview-bindings).
3. (optional) Set the [`ExpandedItems`](https://www.telerik.com/blazor-ui/documentation/components/treeview/expanded-items) attribute to a **non-null** `IEnumerable<object>`. Use it to [expand or collapse items programmatically](https://www.telerik.com/blazor-ui/documentation/components/treeview/expanded-items#programmatically-expand-and-collapse-items).

> caption TreeView with flat self-referencing data and icons

<demo metaUrl="client/treeview/overview/example-1/" height="420"></demo>

## Data Binding

The [TreeView provides flexible data binding](https://www.telerik.com/blazor-ui/documentation/components/treeview/data-binding/overview) with the following capabilities:

* [Binding to flat data](https://www.telerik.com/blazor-ui/documentation/components/treeview/data-binding/flat-data) (self-referencing data)
* [Binding to hierarchical data](https://www.telerik.com/blazor-ui/documentation/components/treeview/data-binding/hierarchical-data). It is possible to use different types for the items at different levels.
* [Loading child items on demand](https://www.telerik.com/blazor-ui/documentation/components/treeview/data-binding/load-on-demand) to improve performance
* [Setting property names](https://www.telerik.com/blazor-ui/documentation/components/treeview/data-binding/overview#treeview-bindings) for item IDs, text, parent IDs, icons, links, etc.

## Selection

The TreeView supports two selection modes:

* [Standard selection](https://www.telerik.com/blazor-ui/documentation/components/treeview/selection/overview) via item clicks
* [Checkbox selection](https://www.telerik.com/blazor-ui/documentation/components/treeview/checkboxes/overview) that allows selecting all child items at once

## Templates

Use [templates to customize the TreeView item rendering](https://www.telerik.com/blazor-ui/documentation/components/treeview/templates). Define a single template for all levels, or a [different template for each level](https://www.telerik.com/blazor-ui/documentation/components/treeview/templates#different-templates-for-different-node-levels).

## Drag and Drop

Users can [drag and drop TreeView items](https://www.telerik.com/blazor-ui/documentation/components/treeview/drag-drop) within the same TreeView or between different ones.

## Navigate Views

The TreeView can [display links to app views and external pages](https://www.telerik.com/blazor-ui/documentation/components/treeview/navigation).

## TreeView Parameters

The following table lists TreeView parameters, which are not related to other features on this page. Check the [TreeView API Reference](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.teleriktreeview) for a full list of properties, methods and events.

<style>
    .article table {
        table-layout: auto;
        word-break: normal;
    }
</style>

| Parameter              | Type and Default Value | Description                                                                                                                                                                                                                                                                                                                                                                       |
| ---------------------- | ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Class`                | `string`               | The additional CSS class that will be rendered on the `div.k-treeview` element. Use it to apply custom styles or [override the theme](https://www.telerik.com/blazor-ui/documentation/styling-and-themes/override-theme-styles).                                                                                                                                                  |
| `Size`                 | `string` <br /> `"md"` | Affects the TreeView layout, for example the amount of space between items. The possible valid values are `"lg"` (large), `"md"` (medium) and `"sm"` (small). For easier setting, use the predefined string properties in class [`Telerik.Blazor.ThemeConstants.TreeView.Size`](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.themeconstants.treeview.size). |
| `DragThrottleInterval` | `int` <br /> (`0`)     | The milliseconds between each firing of the `OnDrag` event during the dragging operations.                                                                                                                                                                                                                                                                                        |

## TreeView Reference and Methods

To execute TreeView methods, obtain reference to the component instance via `@ref`.

The TreeView is a generic component. Its type depends on the type of its model and the type of its `Value`. In case you cannot provide either the `Value` or `Data` initially, you need to [set the corresponding types to the `TItem` and `TValue` parameters](https://www.telerik.com/blazor-ui/documentation/common-features/data-binding/overview#component-type).

The table below lists the TreeView methods. Also consult the [TreeView API](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.teleriktreeview).

| Method                                         | Description                                                                                                                                                                                    |
| ---------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Rebind`                                       | [Refreshes the component data](https://www.telerik.com/blazor-ui/documentation/components/treeview/refresh-data#rebind-method).                                                                |
| `GetItemFromDropIndex` <br /> `(string index)` | gets the corresponding `TItem` of the destination TreeView from the passed [`DestinationIndex`](https://www.telerik.com/blazor-ui/documentation/components/grid/row-drag-drop#event-arguments) |

> caption TreeView reference

```RAZOR.skip-repl
<TelerikTreeView @ref="@TreeViewRef" .../>

@code{
    private TelerikTreeView TreeViewRef;
}
```

## Next Steps

* [Review TreeView data binding](https://www.telerik.com/blazor-ui/documentation/components/treeview/data-binding/overview)
* [Experiment with TreeView Checkboxes](https://www.telerik.com/blazor-ui/documentation/components/treeview/checkboxes/overview)

## See Also

* [Live TreeView Demos](https://demos.telerik.com/blazor-ui/treeview/overview)
* [TreeVew API Reference](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.teleriktreeview)
* [Enable TreeView Scrolling](https://www.telerik.com/blazor-ui/documentation/knowledge-base/treeview-horizontal-scrollbar)
