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

AllowRecursiveSelection and SelectedItems

3 Answers 84 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
JP
Top achievements
Rank 1
JP asked on 14 Apr 2016, 08:04 AM

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!

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 19 Apr 2016, 07:27 AM
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.
0
Walter Edwards
Top achievements
Rank 1
answered on 19 Mar 2017, 10:38 PM
I have the exact same problem.
0
Eyup
Telerik team
answered on 22 Mar 2017, 05:01 PM
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.
Tags
TreeList
Asked by
JP
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Walter Edwards
Top achievements
Rank 1
Share this question
or