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

Get SelectedItems for the treelist with multiple pages

3 Answers 155 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Uday
Top achievements
Rank 1
Uday asked on 23 Feb 2011, 01:49 PM
I have treelist, which have multiple pages.
User can select some items on first page, using pager can move to next page and select some other records.

On save, I am trying to read the Treelist's Selected Items, property, its giving only records selected on the current page and not from the last page.

Is it by design or do I need to configure some properties to achieve this ?

While moving between pages, selection is preserved.

3 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 25 Feb 2011, 10:55 AM
Hello Uday,

This is by design. At any point in RadTreeList, you have access to the visible data items only. Items in other pages, and children that are not visible are not available. Selection is preserved, because we persist the selected indexes between pages and rebinds, but data items are created for the visible records only.

Veli
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Keith
Top achievements
Rank 1
answered on 14 Apr 2011, 08:37 AM
Veli,
Is there a way for me to access the selected indexes you mentioned?

I need to find out if any children are selected when the parent is collapsed. If this is absolutely not possible, is there a way for me to prevent collapsing a parent node when children are selected?
0
Veli
Telerik team
answered on 15 Apr 2011, 10:24 AM
Selected indexes are not exposed in the public API. You can, however implement a method that will return the number of selected child items for a specified TreeListDataItem. You can then use this method to prevent collapsing if any child item is selected:

protected void RadTreeList1_ItemCommand(object sender, TreeListCommandEventArgs e)
{
    if (e.CommandName == RadTreeList.ExpandCollapseCommandName)
    {
        TreeListDataItem dataItem = (TreeListDataItem)e.Item;
        if (GetSelectedChildrenCount(dataItem) > 0)
        {
            e.Canceled = true;
        }
    }
}
 
protected int GetSelectedChildrenCount(TreeListDataItem dataItem)
{
    int selectedCount = 0;
    bool beginTrack = false;
 
    foreach (TreeListDataItem item in RadTreeList1.Items)
    {
        //if current item is at the same hierarchy level
        if (item.HierarchyIndex.NestedLevel == dataItem.HierarchyIndex.NestedLevel)
        {              
            if (item == dataItem)
            {
                //track items from the current item onwards
                beginTrack = true;
            }
            else if (item.HierarchyIndex.LevelIndex > dataItem.HierarchyIndex.LevelIndex)
            {
                //the current item is the next item in the same hierarchy level as dataItem
                //so, we have gone through any existing child items of dataItem
                break;
            }
        }
        else if (item.HierarchyIndex.NestedLevel > dataItem.HierarchyIndex.NestedLevel)
        {               
            if (beginTrack)
            {
                //this will execute for child items of the specified dataItem only
                if (item.Selected)
                {
                    selectedCount++;
                }
            }
        }
    }
 
    return selectedCount;
}

GetSelectedChildrenCount() in the above code sample retrieves the number of selected items for a specified data item.

Veli
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
TreeList
Asked by
Uday
Top achievements
Rank 1
Answers by
Veli
Telerik team
Keith
Top achievements
Rank 1
Share this question
or