ContainerFromItemRecursive and IsSelected

4 posts, 0 answers
  1. Antonio
    Antonio avatar
    6 posts
    Member since:
    Jun 2012

    Posted 20 Apr 2010 Link to this post

    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
  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 23 Apr 2010 Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Antonio
    Antonio avatar
    6 posts
    Member since:
    Jun 2012

    Posted 28 Apr 2010 Link to this post

    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

  5. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 30 Apr 2010 Link to this post

    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.
Back to Top