# Node Selection

## Content



When you click on a node at run time it is automatically marked as selected. Clicking a node will raise the [SelectionChanged](/componentone/api/wpf/online-treeview5/dotnet-api/C1.WPF.TreeView/C1.WPF.TreeView.C1TreeView.SelectionChanged.html) event to provide custom functionality. To have the nodes marked as selected without clicking them you can enable the [IsSelected](/componentone/api/wpf/online-treeview5/dotnet-api/C1.WPF.TreeView/C1.WPF.TreeView.C1TreeViewItem.IsSelected.html) property.

When the user selects a new item, the C1TreeView fires the **SelectionChanged** event. You can then retrieve the item that was selected using the [SelectedItem](/componentone/api/wpf/online-treeview5/dotnet-api/C1.WPF.TreeView/C1.WPF.TreeView.C1TreeView.SelectedItem.html) property.

There are several ways to do this. Two are discussed in the following content.

You can also get the **Text** or **Value** of the **C1TreeViewItem** **Header** property using the **SelectedItem** property.

**Selecting Items with the Tag Property**

One is to assign additional data to the **Tag** property of each [C1TreeViewItem](/componentone/api/wpf/online-treeview5/dotnet-api/C1.WPF.TreeView/C1.WPF.TreeView.C1TreeViewItem.html) as you create them. Later, you can inspect the **Tag** property to retrieve the information. For example:

```vbnet
' Create a node and assign some data to its Tag property
Dim item As New C1TreeViewItem()
item.Header = "Beverages"
item.Tag = beveragesID
```

```csharp
// Create a node and assign some data to its Tag property
C1TreeViewItem item = new C1TreeViewItem();
item.Header = "Beverages";
item.Tag = beveragesID;
```

Later, use the information in whatever way you see fit:

```vbnet
Dim item As C1TreeViewItem = _tv.SelectedItem
' Handle beverages node
If TypeOf item.Tag Is Integer AndAlso CInt(item.Tag) = beveragesID Then
End If
```

```csharp
C1TreeViewItem item = _tv.SelectedItem;
if (item.Tag is int && (int)item.Tag == beveragesID)
{
    // Handle beverages node
}
```

**Selecting Items with a Checkbox**

You can also allow users to select **C1TreeViewItem**s with a checkbox. To add a checkbox to your **C1TreeViewItem**s, use the following markup:

```xml
<c1:C1TreeView Name="C1TreeView1" Height="300" Width="200" >
    <c1:C1TreeViewItem IsExpanded="True" Margin="10">
        <c1:C1TreeViewItem.Header>
            <CheckBox>
                <CheckBox.Content>
                    <TextBlock Text="Desktop" />
                </CheckBox.Content>
            </CheckBox>
        </c1:C1TreeViewItem.Header>
    <c1:C1TreeViewItem>
        <c1:C1TreeViewItem.Header>
            <CheckBox>
                <CheckBox.Content>
                    <TextBlock Text="User" />
                </CheckBox.Content>
            </CheckBox>
        </c1:C1TreeViewItem.Header>
    </c1:C1TreeViewItem>   
</c1:C1TreeView>
```

**Getting the Text or Value of a Selected Item**

The **Header** property will return the values contained in your **C1TreeViewItem**s, you can get the string value using the following code:

```vbnet
Dim item As C1TreeViewItem = _tree.SelectedItem
_textBlock.Text = item.Header.ToString()
```

```csharp
C1TreeViewItem item = _tree.SelectedItem;
_textBlock.Text = item.Header.ToString();
```