When you click on a node at run time it is automatically marked as selected. Clicking a node will raise the SelectionChanged event to provide custom functionality. To have the nodes marked as selected without clicking them you can enable the IsSelected 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 property.
There're several ways to do this. One is to assign additional data to the Tag property of each C1TreeViewItem as you create them. Later, you can inspect the Tag property to retrieve the information. For example:
' Create a node and assign some data to its Tag property
Dim item As New C1TreeViewItem()
item.Header = "Beverages"
item.Tag = beveragesID
•C#
// 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:
Dim item As C1TreeViewItem = _tv.SelectedItem
' Handle beverages node
If TypeOf item.Tag Is Integer AndAlso CInt(item.Tag) = beveragesID Then
End If
•C#
C1TreeViewItem item = _tv.SelectedItem;
if (item.Tag is int && (int)item.Tag == beveragesID)
{
// Handle beverages node
}
If the SelectionMode property is set to Multiple then multiple nodes can be selected at one time by holding down the control key while mouse clicking multiple nodes. To unselect a node, click on it again. The nodes are marked as selected in the following C1TreeView: