# Tree View

`New-UDTreeView` allows you to create a tree of items and, optionally, dynamically expand the list when clicked.

## Basic Tree View

Create a basic tree view by using the `New-UDTreeNode` cmdlet.

```powershell
New-UDTreeView -Node {
    New-UDTreeNode -Name 'Level 1' -Children {
        New-UDTreeNode -Name 'Level 2 - Item 1' 
        New-UDTreeNode -Name 'Level 2 - Item 2'
        New-UDTreeNode -Name 'Level 2 - Item 3' -Children {
            New-UDTreeNode -Name 'Level 3'
        }
    }
}
```

![Basic Tree View](/files/-MJ3BMGlYlwAoec6dZqq)

## Dynamic Tree View

Dynamic tree views allow you to run PowerShell whenever a node is clicked. You can then return a list of nodes that should be rendered underneath the clicked node. You can also take other actions such as opening a modal or showing a toast.

```powershell
New-UDDashboard -Title 'File System' -Content {
    Get-PSDrive -PSProvider 'FileSystem' | ForEach-Object {
        New-UDTreeView -Node { New-UDTreeNode -Name $_.Name -Id "$($_.Name):\" } -OnNodeClicked {
            Get-ChildItem $EventData.Id | ForEach-Object {
                New-UDTreeNode -Name $_.Name -Id $_.FullName -Leaf:$(-not $_.PSIsContainer)
            }
        }
    }
}
```

<figure><img src="/files/ErPd5hXAQ6W6rZM3riRM" alt=""><figcaption></figcaption></figure>

## API

* [New-UDTreeView](https://github.com/ironmansoftware/universal-docs/blob/master/cmdlets/New-UDTreeView.txt)
* [New-UDTreeNode](https://github.com/ironmansoftware/universal-docs/blob/master/cmdlets/New-UDTreeNode.txt)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.powershelluniversal.com/v4-beta/userinterfaces/components/data-display/tree-view.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
