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

[Solved] Checked node from code-behind

1 Answer 162 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
T.Y.
Top achievements
Rank 1
T.Y. asked on 23 Apr 2009, 12:09 PM
I use with the RadTreeView control -
RadTreeView radTreeView = new RadTreeView ();

I created 
class DataItem()
{
...
List<<DataItem> Items  {get; set;}
}  
in the Page.cs I created a list<DataItem> items  and I was enter my data into it.
radTreeView.ItemSource=items;.
when its run the tree is display.

But I have one problem-
 when I load the application I want a few tree view items to be checked.
I can not  write: radTreeView .Items[0].CheckState  because it "DataItem type and not radTreeViewItem type

how can I do the node to be checked?

thanks

1 Answer, 1 is accepted

Sort by
0
Bobi
Telerik team
answered on 24 Apr 2009, 12:57 PM
Hi Toybi,

You can try the following:

1.Subscribe to RadtreeView's Loaded event:

     this.treeView.Loaded += new RoutedEventHandler(TreeView_Loaded);

2.Add the following code:

private void TreeView_Loaded(object sender, RoutedEventArgs e)
        {
            RadTreeViewItem item = treeView.ItemContainerGenerator.ContainerFromIndex(1) as RadTreeViewItem;
            if(item != null)
            {
                item.CheckState = System.Windows.Automation.ToggleState.On;
            }
        }

These examples demonstrate how to get an instance of the item with index "1" and set the CheckState. In the same way you can get whatever item from the collection of items.

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
CheckState property to the desired value.

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
T.Y.
Top achievements
Rank 1
Answers by
Bobi
Telerik team
Share this question
or