We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Collapsing of groups

I have a data table shown in a grouping grid and refresh the table using dataTable.Clear() dataAdapter.Fill(dataTable) After I have done this, all the groups of the grid are collapsed. If I omit dataTable.Clear() the groups are not collapsed, but then my data table will not reflect the changes correctly if any records are deleted from the data base. Is there any simple way I can fix this so that the grouping status of the grid does not change after the refresh operation? (Of cource if the structure of the table has changed completely the grouping status must also change.)

2 Replies

AD Administrator Syncfusion Team June 2, 2005 08:36 AM

I think the reason you are seeing this behavior is that when all the records from a group are removed, that group is marked as collapsed and stays that way event if you add new records later. One solution might be to add code that remembers the dataTable.Rows.Count before your call to adapter.Fill. Then afterwards have code like:
for(int i = 0; i < oldRowCount; ++i)
{
    dataTable.Rows.RemoveAt(0);
}

This would add all the new records first, and then remove the old ones later. (without calling DataTable.Clear). In this case, I think the expand state would remain as before. This does assume the DataTable schema does not change.
            


AD Administrator Syncfusion Team June 2, 2005 10:36 AM

I believe a problem with this solution is that the adapter will replace instead of adding rows with the same primary key. Thus, one risk to delete rows that were just read. Instead, I tried to loop through all groups and save the expanded/collapsed state. After reading the new data, I search for the same groups and set the expanded/collapsed state. This seems to work fine.

Loader.
Live Chat Icon For mobile
Up arrow icon