Enumerating a node's children

6 posts, 1 answers
  1. jogi
    jogi avatar
    7 posts
    Member since:
    Sep 2008

    Posted 13 Oct 2008 Link to this post

    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
  2. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 15 Oct 2008 Link to this post

    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.
  3. jogi
    jogi avatar
    7 posts
    Member since:
    Sep 2008

    Posted 20 Oct 2008 Link to this post

    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
  4. jogi
    jogi avatar
    7 posts
    Member since:
    Sep 2008

    Posted 20 Oct 2008 Link to this post

    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

     

     

     

     

  5. Answer
    Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 21 Oct 2008 Link to this post

    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.
  6. jogi
    jogi avatar
    7 posts
    Member since:
    Sep 2008

    Posted 21 Oct 2008 Link to this post

    Exactly what I'm looking for.  Thanks!

    -jo
Back to Top