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

Problems with Exand HeaderRow - Items not visible

2 Answers 32 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Torsten
Top achievements
Rank 1
Torsten asked on 20 Apr 2011, 10:19 AM
I have a grouped grid where user can select the whole group or just some groupmembers. If the whole group is selected, the groupitems shouldn't be displayed. If only one or more groupmembers are selected, the group should be expanded.

So I used this code (simplified):

SortedList

 

<string, GridGroupHeaderItem> headerItems = new SortedList<string, GridGroupHeaderItem>();

 


protected
void rtl_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridGroupHeaderItem)
            {
                GridGroupHeaderItem item = (GridGroupHeaderItem)e.Item;
                  
                headerItems.Add(groupDataRow["Betriebegruppe"].ToString(), item);
  
            }
            else if (e.Item is GridItem)
            {
                GridItem item = (GridItem)e.Item;
                  
                item.Selected = dataBase.checkIsItemSelected(item);
                        
                if (item.Selected && !headerItems[dataRow.Betriebegruppe].Expanded)
                {                   
                    headerItems[dataRow.Betriebegruppe].Expanded = true;
                }
            }
        }

Now, if the headerItems[...].Expanded is set to true, the group expands, but all items which are added after this assignment are set to style="display:none" and are only visible if I collapse and expand in client.

How can I fix this behavior?

2 Answers, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 26 Apr 2011, 11:15 AM
Hello Torsten,

To achieve the desired functionality I suggest you to apply your custom logic into the RadGrid.PreRender event instead of on RadGrid1_ItemDataBound. Into the RadGrid.PreRender event you could get all GridGroupHeaderItems and theirs child GridItems with the following code:
void RadGrid1_PreRender(object sender, EventArgs e)
    {
        GridItem[] items = RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader);
        foreach (GridGroupHeaderItem item in items)
        {
            if (item.HasChildItems)
            {
                // Get all items wich belongs to the group
                GridItem[] childItems = item.GetChildItems();
            }
            if (SomeCondition)
            {
                item.Expanded = true;
            }
        }
 
    }

Please give it try and let me know if you experience any problems.

Best wishes,
Radoslav
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.

0
Torsten
Top achievements
Rank 1
answered on 26 Apr 2011, 01:38 PM
This works for me.

THX!!
Tags
Grid
Asked by
Torsten
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Torsten
Top achievements
Rank 1
Share this question
or