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

Check Treeview items

4 Answers 112 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Indu VS
Top achievements
Rank 1
Indu VS asked on 18 Dec 2009, 08:07 AM
Hi,

I am using a radtreeview and i want to make some treeviewitems checked while the tree is loading(in the tree_loaded event).
The problem is that I couldn't retrieve the treeviewitems. I used itemcontainergenerator, but its status is always showing as 'Not Started'. I tried by expanding the tree .Also tried using dispatcher. But still not working.  Could anyone help me?

4 Answers, 1 is accepted

Sort by
0
Valentin.Stoychev
Telerik team
answered on 21 Dec 2009, 07:41 AM
Hi Indu VS,

Please check this help article:
http://www.telerik.com/help/silverlight/radtreeview-how-to-iterate-through-treeviewitems.html


Kind regards,
Valentin.Stoychev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Indu VS
Top achievements
Rank 1
answered on 22 Dec 2009, 10:28 AM

Hi..
thanks for your reply. i tried the same example code as given below

 private void GetContainers()
        {
            // gets all nodes from the TreeView 
            Collection<RadTreeViewItem> allTreeContainers = GetAllItemContainers(this.itemSourceTree);
            // gets all nodes (recursively) for the first node 
            RadTreeViewItem firstNode = this.itemSourceTree.ItemContainerGenerator.ContainerFromIndex(0) as RadTreeViewItem;
            if (firstNode != null)
            {
                Collection<RadTreeViewItem> firstNodeContainers = GetAllItemContainers(firstNode);
            }
        }

        private Collection<RadTreeViewItem> GetAllItemContainers(Telerik.Windows.Controls.ItemsControl itemsControl)
        {
            Collection<RadTreeViewItem> allItems = new Collection<RadTreeViewItem>();
            for (int i = 0; i < itemsControl.Items.Count; i++)
            {
                // try to get the item Container 
                RadTreeViewItem childItemContainer = itemsControl.ItemContainerGenerator.ContainerFromIndex(i) as RadTreeViewItem;
                // the item container maybe null if it is still not generated from the runtime 
                if (childItemContainer != null)
                {
                    allItems.Add(childItemContainer);
                    Collection<RadTreeViewItem> childItems = GetAllItemContainers(childItemContainer);
                    foreach (RadTreeViewItem childItem in childItems)
                    {
                        allItems.Add(childItem);
                    }
                }
            }
            return allItems;
        }  

    private void itemSourceTree_Loaded(object sender,RoutedEventArgs e)
    {

                 this.GetContainers();
    }

But it is also not working. I am getting "childItemContainer"  always null.  What should i do?

0
Valentin.Stoychev
Telerik team
answered on 22 Dec 2009, 11:53 AM
Hi Indu VS,

If the item is not expanded its children are not prepared from the silverlight framework - e.g. they do not exist. This is why you get null for the item. You need to use the ItemPrepared event in your case. Please check this forum post:
http://www.telerik.com/community/forums/silverlight/treeview/check-uncheck-radtreeviewitem-not-take-affect-in-children-node.aspx

Best wishes,
Valentin.Stoychev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Indu VS
Top achievements
Rank 1
answered on 23 Dec 2009, 12:16 PM
Hi
Thanks for your immediate reply. In itemprepared event, i am getting each treeviewitem. So i think that will solve my problem.
Tags
TreeView
Asked by
Indu VS
Top achievements
Rank 1
Answers by
Valentin.Stoychev
Telerik team
Indu VS
Top achievements
Rank 1
Share this question
or