Home / Community & Support / Knowledge Base / RadControls for WPF / TreeView / How do I get the RadTreeViewItem

How do I get the RadTreeViewItem

Article Info

Rating: 5

Article information

Article relates to

 Accessing RadTreeViewItem via ContainerFromItemRecursive

Created by

 Ivan Efimov

Last modified

 04-13-2009

Last modified by

 



Working with data-bound TreeView involves one confusing moment - SelectedItem do not refers to a RadTreeViewItem but an item from the ItemsSource collection. To access the related tree-view item we have to address the ContainerFromItemRecursive method:

object item = myTree.SelectedItem; 
if (item != null
    RadTreeViewItem tvi = myTree.ContainerFromItemRecursive(myTree.SelectedItem); 
    if (tvi != null
    { 
        // here we can deal with the tree-view item 
        // ... 
    } 

According to this state we should care when accessing SelectedItem property.

In attached archive you can find an example how to access the Container of SelectedItem.

Note: Data-binding of the TreeView control is realized as it is described in the How to Databind RadTreeView in WPF article.

Files

Comments

If you'd like to comment on this KB article, please, send us a Support Ticket.
Thank you!

Please Sign In to rate this article.