Saturday, January 5, 2013

In a 'customized' DataGrid why a RowGroup shrinks another?

In a 'customized' DataGrid why a RowGroup shrinks another?

I have a very strange issue with a DataGrid. Luckily I could do the scenario in a tiny example, the solution is uploaded here, download it and go to the last part of this question 'Steps to destroy an Datagrid.' or you can follow this steps.

First download the example of Kunal Chowdhury.

Set the PageSize property of the DataPager bigger than 8, and collapsed it. Set the DataGrid Height property to "Auto". In the method GetEmployeeDetails of the Class EmployeeProviders, set all State property to empty State = "" except for one Item, for example the first State = "Maharashtra":

After this the DataGrid looks like: State 1

Then we want to hide the empty RowGroup, and for that we add the event LoadingRowGroup of the DataGrid:

    private void DataGrid_LoadingRowGroup(object sender, DataGridRowGroupHeaderEventArgs e)     {         CollectionViewGroup oRowGroupHeader = (e.RowGroupHeader.DataContext as CollectionViewGroup);          if (oRowGroupHeader != null && oRowGroupHeader.Items.Count > 0)         {             Employee oTask = oRowGroupHeader.Items[0] as Employee;             if (oTask != null && String.IsNullOrWhiteSpace(oTask.State))                 e.RowGroupHeader.Visibility = System.Windows.Visibility.Collapsed;         }     } 

After changes, the DataGrid looks:

State2

Everything is fine, 'the requirement was made perfectly', but...

There a scenario where the DataGrid is unstable.

Steps to destroy an Datagrid.

  1. Collapse/shrink every father RowGroup, the datagrid must show only 4 rows { Silverlight, ASP.Net, CSharp, WCF }
  2. Expand the last RowGroup : "WCF"
  3. Expand the first Rowgroup : "Silverlight"

State 3

Surprise now you'll see only 3 RowGroup, what happened to the DataGrid, maybe there is a better approach for my requirement?

Many Thanks.

Answers & Comments...




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog