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
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.
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?
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.
Thanks for your immediate reply. In itemprepared event, i am getting each treeviewitem. So i think that will solve my problem.