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

ContainerFromItemRecursive and IsSelected

3 Answers 99 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Antonio
Top achievements
Rank 1
Antonio asked on 20 Apr 2010, 09:33 AM
We have a treeView with data populated programmatically using:
ObservableCollection<MyInterface> items = new ObservableCollection<MyInterface>(); 
this.myTreeView.ItemsSource = items; 
Now we would like to select item from different "external" events on this way:
RadTreeViewItem rtvi = this.myTreeView.ContainerFromItemRecursive(currentItem); 
rtvi.IsSelected = true
Actually the rtvi object seems to be found and correct....but we don't see any changes on the controls.

Any way to do it with that approach?
Thanxs.
Alex

3 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 23 Apr 2010, 02:31 PM
Hello Alex,

I tried this and it works as expected on our side.

Please take a look at the attached project and let me know if it works for you.

Best wishes,
Tina Stancheva
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Antonio
Top achievements
Rank 1
answered on 28 Apr 2010, 06:30 PM
Really thanks Tina,
with your example i found where is the problem,
actually i have a tree with a lot of items and not all the items starts Expanded.
Now when i use ContainerFromItemRecursive method with an element into a collapsed item never opened before the method just return null.
If i open the parent treeopen the method ContainerFromItemRecursive works correctly.

What do you think about this scenario?
I think it is related to virtualization or a way to optimize the loading process....any option to force the load of all items even if they start collapsed?

Thanks.
Alex

0
Tina Stancheva
Telerik team
answered on 30 Apr 2010, 05:33 PM
Hi Alex,

The ContainerFromItemRecursive method searches recursively in the tree to get an item container (RadTreeViewItem) for a particular data item. Since the item containers will not be generated until needed (until visible), you will have to handle the ItemContainerGenerator.StatusChanged event and be notified when they are generated.

myTreeView.ItemContainerGenerator.StatusChanged += new EventHandler(ItemContainerGenerator_StatusChanged);
void ItemContainerGenerator_StatusChanged(object sender, EventArgs e)
        {
            if (myTreeView.ItemContainerGenerator.Status == GeneratorStatus.ContainersGenerated)
            {
                   //the custom logic goes here
                   RadTreeViewItem rtvi = this.myTreeView.ContainerFromItemRecursive(dataItem);
            }
        }

I modified the example accordingly. Please take a look at it and let me know if it works for you.

Best wishes,
Tina Stancheva
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
TreeView
Asked by
Antonio
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Antonio
Top achievements
Rank 1
Share this question
or