This is a migrated thread and some comments may be shown as answers.

Select topnode by default

1 Answer 92 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Sunandini
Top achievements
Rank 1
Sunandini asked on 21 Apr 2009, 05:43 PM
I have a WPF desktop app. I have a tree view. I load the tree view using an observable collection. I want to select the topmost node of the tree by default, to start with. But SelectedItem, SelectedValue etc seem to be readonly. Is it possible to select the top node of the tree when I start up?

Thanks

1 Answer, 1 is accepted

Sort by
0
Bobi
Telerik team
answered on 22 Apr 2009, 12:11 PM
Hello Sunandini,

You can try the following:

1.Add some ItemsSource to RadtreeView:
      this.treeView.ItemsSource = listCollection;

2.Subscribe to RadtreeView Loaded :
     this.treeView.Loaded += new RoutedEventHandler(TreeView_Loaded);

3.Add the following code:
private void TreeView_Loaded(object sender, RoutedEventArgs e)
        {
            RadTreeViewItem item = treeView.ItemContainerGenerator.ContainerFromIndex(1) as RadTreeViewItem;
            if(item != null)
            {
            item.IsSelected = true;
            }
        }

In order to select a RadtreeView node all you have to do is simply to get an instance of the desired RadtreeViewItem and set its IsSelected property to true.

Note:If you use binding you can get the desired RadTreeViewItem  by using  the following:
      
ItemContainerGenerator.ContainerFromIndex(index) or ItemContainerGenerator.ContainerFromItem(item).

I hope this answers your question.


Best wishes,
Boryana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
TreeView
Asked by
Sunandini
Top achievements
Rank 1
Answers by
Bobi
Telerik team
Share this question
or