---
title: Expand and collapse TreeView items on click
description: How to expand and collapse the parent TreeView items when clicking on them?
type: how-to
page_title: Expand and collapse TreeView items on click
slug: treeview-kb-expand-collapse-on-item-click
position:
tags: treeview, item, expand, collapse, click, onclick
ticketid: 1583333
res_type: kb
---
## Environment
Product
TreeView for Blazor
## Description
Currently, I am able to expand or collapse the parent TreeView items only when I click on their arrow buttons.
How can I expand the items when I click on their text? Is it also possible to collapse an item when I click it?
## Solution
By design, the parent TreeView items are expanded or collapsed on click of the expand/collapse icon that is rendered next to the item.
To expand a TreeView item when you click on it:
* Handle the [TreeView `OnItemClick` event](slug:treeview-events#onitemclick).
* Verify if the clicked item is a parent, so it can be expanded:
* For [flat data](slug:components/treeview/data-binding/flat-data) check if `HasChildren` field equals `true`.
* For [hierarchical data](slug:components/treeview/data-binding/hierarchical-data) check if the `Items` field (or your custom field name) contains any child items.
* Check if the clicked item exists in the [`ExpandedItems`](slug:treeview-expand-items) collection:
* If the clicked item is not part of the collection, you may add it to programmatically expand it.
* If the clicked item is already part of the collection, this means the item is currently expanded. You may programmatically collapse it by removing it from the `ExpandedItems`.
>caption Expand and collapse TreeView items on click
````RAZOR
@*Expand and collapse items on click in TreeView with flat data.*@
@code {
private IEnumerable