5 Answers, 1 is accepted
You can not enumerate the item containers, because they are not generated until they are expanded. Please
check this forum thread for more info in this concept:
http://www.telerik.com/community/forums/thread/b311D-begaeb.aspx
Also check-out this online examples for more about the container generation:
http://demos.telerik.com/silverlight/#Examples/TreeView/AccessingItems
What scenario you have? Why you need to enumerate the RadTreeViewItems?
Regards,
Valentin.Stoychev
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
I'm just trying to get a list of objects of all the nodes that have been selected for a particular TreeViewItem. I've started to write an extension method to handle this for me but the IsSelected property doesn't seem to work. Am I checking the wrong property? Thanks. Here is the code:
public
static List<RadTreeViewItem> SelectedItemsX(this RadTreeViewItem treeView)
{
if (treeView == null) throw new ArgumentNullException();
var treeViewItemList = new List<RadTreeViewItem>();
var list = treeView.ItemsSource as IEnumerable;
if (list == null)
return treeViewItemList;
foreach (var item in list)
{
var itemFound = treeView.ParentTreeView.ContainerFromItemRecursive(item);
//IsSelected here never seems to return true
if (itemFound != null && itemFound.IsSelected == true)
treeViewItemList.Add(itemFound);
}
return treeViewItemList;
}
Thanks.
-jo
Looks like using IsSelected is for node selections rather than checking checkbox items. Replacing the IsSelected line with this:
if (itemFound != null && itemFound.CheckState == System.Windows.Automation.ToggleState.On)
Works but doesn't seem incredibly efficient because I need to call that recursive function for each item. Any ideas? Thanks.
-jo
We have a CheckedItems Collection which you can use for this purpose. See this online example for more info:
http://demos.telerik.com/silverlight/#Examples/TreeView/CheckedNodes
You need to handle the changes on that selection and to filter it according to you criteria (in your case if the items is a child of the TreeViewItem that you are inspecting).
Please let us know if you have any other questions.
Sincerely yours,
Valentin.Stoychev
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
-jo