AllowRecursiveSelection and SelectedItems

4 posts, 0 answers
  1. JP
    JP avatar
    120 posts
    Member since:
    Aug 2011

    Posted 14 Apr 2016 Link to this post

    Hi,

    I'm using a RadTreeList with data bound using a DataTable in NeedDataSource.

    I set AllowRecursiveSelection to true so that all child nodes are selected too, even if they are not expanded.

    Unfortunately, it doesn't work as expected. If I check SelectedItems on the server, I only get a list containing the currently VISIBLE selected items. The child items are not included. If I expand this selected node, the children are selected as expected and appear in the SelectedItems. If I collapse the node again, they don't appear in SelectedItems anymore.

    Also, the Items property only contains the currently VISIBLE items,  I expected it to contain all items.

    The SelectedIndexes property is always correct, but I don't know how I could use this information to find the according data in the DataTable.

     

    What do I have to do to get SelectedItems to return the invisble selected items too?

    Thanks!

  2. Eyup
    Admin
    Eyup avatar
    3175 posts

    Posted 19 Apr 2016 Link to this post

    Hello,

    I've already replied in your ticket with ID: 1027929. I suggest that we continue our conversation on the mentioned thread.

    Regards,
    Eyup
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  3. Walter Edwards
    Walter Edwards avatar
    1 posts
    Member since:
    Feb 2006

    Posted 19 Mar in reply to Eyup Link to this post

    I have the exact same problem.
  4. Eyup
    Admin
    Eyup avatar
    3175 posts

    Posted 22 Mar Link to this post

    Hello,

    I am copying the replies here to so other developers may find it helpful as well:

    1. First reply:

    Only the visible items of the RadTreeList are loaded at a time, therefore, it is not possible to access the invisible child items of a collapsed parent record, simply because they are not created yet. Therefore, you can temporarily expand all of the items when you want to access the selected items through the entire collection:
    protected void Button1_Click(object sender, EventArgs e)
    {
        RadTreeList1.ExpandAllItems();
        StringBuilder sb = new StringBuilder();
        sb.AppendLine("Selected items info:<br/><br/>");
        foreach (TreeListDataItem item in RadTreeList1.SelectedItems)
        {
            string dataKeyID = item.GetDataKeyValue("RecordID").ToString();
            string name = item["Name"].Text;
            string location = item["Location"].Text;
     
            sb.AppendLine(string.Format(@"<b>DataKeyID:</b> {0}, <b>Name:</b> {1},
                                              <b>Location:</b> {2} <br/>",
                                       dataKeyID, name, location));
        }
     
        Label1.Text = sb.ToString();
        RadTreeList1.CollapseAllItems();
    }

    2. Second reply

    I've modified to logic to apply the requested improvement:
    TreeListExpandedIndexesCollection expandedIndexes;
    protected void Button1_Click(object sender, EventArgs e)
    {
        expandedIndexes = new TreeListExpandedIndexesCollection();
        expandedIndexes.AddRange(RadTreeList1.ExpandedIndexes);
        RadTreeList1.ExpandAllItems();
        StringBuilder sb = new StringBuilder();
        sb.AppendLine("Selected items info:<br/><br/>");
        foreach (TreeListDataItem item in RadTreeList1.SelectedItems)
        {
            string dataKeyID = item.GetDataKeyValue("RecordID").ToString();
            string name = item["Name"].Text;
            string location = item["Location"].Text;
     
            sb.AppendLine(string.Format(@"<b>DataKeyID:</b> {0}, <b>Name:</b> {1},
                                              <b>Location:</b> {2} <br/>",
                                       dataKeyID, name, location));
        }
     
        Label1.Text = sb.ToString();
        foreach (TreeListDataItem treeListItem in RadTreeList1.Items)
        {
            TraverseAllItems(treeListItem);
        }
    }
    public void TraverseAllItems(TreeListDataItem item)
    {
        if (!expandedIndexes.Contains(item.HierarchyIndex))
        {
            item.Expanded = false;
        }
        if (item.ChildItems.Count > 0)
        {
            foreach (TreeListDataItem childItem in item.ChildItems)
            {
                TraverseAllItems(childItem);
            }
        }
        return;
    }

    I hope this will prove helpful.


    Regards,
    Eyup
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top