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

Enumerating a node's children

5 Answers 129 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
jogi
Top achievements
Rank 1
jogi asked on 13 Oct 2008, 08:34 PM
Hi,

I'm trying to enumerate a RadTreeViewItem's children RadTreeView items with no luck.  I tried using the Items property but it seems to return the underlying bound data.  Thanks.
-jo

5 Answers, 1 is accepted

Sort by
0
Valentin.Stoychev
Telerik team
answered on 15 Oct 2008, 02:09 PM
Hello John,

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.
0
jogi
Top achievements
Rank 1
answered on 20 Oct 2008, 05:31 PM
Hi Valentin,

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
0
jogi
Top achievements
Rank 1
answered on 20 Oct 2008, 08:29 PM

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

 

 

 

 

0
Accepted
Valentin.Stoychev
Telerik team
answered on 21 Oct 2008, 07:29 AM
Hello John,

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.
0
jogi
Top achievements
Rank 1
answered on 21 Oct 2008, 04:28 PM
Exactly what I'm looking for.  Thanks!

-jo
Tags
TreeView
Asked by
jogi
Top achievements
Rank 1
Answers by
Valentin.Stoychev
Telerik team
jogi
Top achievements
Rank 1
Share this question
or