Wednesday, October 31, 2012

Datagrid Grouping collapsed issue

Datagrid Grouping collapsed issue

Hello Team,

We have developed a silverlight 4 application and populated data using Datagrid.This Datagrid has grouping functionality and as we know by default all groups were expanded but as per our requirement we are trying to collapse all groups.

We have nearly 7000 records and by using following code we were able to collapse all groups but it took 2 to 3 min to complete functionality.Customer not at all statisfied with performance.Can any one help us to improve the performance?

foreach (CollectionViewGroup group in (mainGridTrueUp.ItemsSource as PagedCollectionView).Groups)
{
mainGridTrueUp.CollapseRowGroup(group, true);
}

Here mainGridTrueUp is our datagrid.

Thanks in Advance.

Madhan.

Answers & Comments...

Answer: 1

http://subodhnpushpak.wordpress.com/2009/04/22/collapsing-groups-in-silverlight-datagrid/.

http://forums.silverlight.net/t/224651.aspx

http://forums.silverlight.net/p/217667/518299.aspx



Answer: 2

Have you enabled paging in PagedCollectionView? 

http://msdn.microsoft.com/en-us/library/system.windows.data.pagedcollectionview(v=vs.95).aspx 

http://www.c-sharpcorner.com/uploadfile/subhendude/datagrid-paging-in-silverlight-using-wcf-ria-services/ 



Answer: 3

Is it not possible to collapse groups in datagrid which has datapager? Currently I have a datagrid which has groups but could not collapse groups after applying paging.



Answer: 4

Hi Madhan and Arvind_SL, please refer to below code for grouping and paging in DataGrid in Silverlight.

            <data:DataPager x:Name="dataPager1"                              PageSize="5"                              AutoEllipsis="True"                              NumericButtonCount="3"                              DisplayMode="FirstLastPreviousNextNumeric"                              IsTotalItemCountFixed="True"/>              <data:DataGrid AutoGenerateColumns="False" Height="Auto" HorizontalAlignment="Left" Margin="10,10,0,0"                         Name="dataGrid1" VerticalAlignment="Top" Width="Auto">                  <data:DataGrid.Columns>                      <!-- Name Column -->                      <data:DataGridTemplateColumn Header="Name">                          <data:DataGridTemplateColumn.CellTemplate>                              <DataTemplate>                                  <StackPanel Orientation="Horizontal" VerticalAlignment="Center">                                      <TextBlock Padding="5,0,5,0"                              Text="{Binding FirstName}" Width="Auto"/>                                      <TextBlock Text="{Binding LastName}" Width="Auto"/>                                  </StackPanel>                              </DataTemplate>                          </data:DataGridTemplateColumn.CellTemplate>                          <data:DataGridTemplateColumn.CellEditingTemplate>                              <DataTemplate>                                  <StackPanel Orientation="Horizontal">                                      <TextBox Text="{Binding FirstName,Mode=TwoWay}" BorderThickness="0" Width="Auto"/>                                      <TextBox Text="{Binding LastName,Mode=TwoWay}" BorderThickness="0" Width="Auto"/>                                  </StackPanel>                              </DataTemplate>                          </data:DataGridTemplateColumn.CellEditingTemplate>                      </data:DataGridTemplateColumn>                      <!-- Address Column -->                      <data:DataGridTextColumn              Header="Address" Width="Auto"              Binding="{Binding Address}" />                  </data:DataGrid.Columns>              </data:DataGrid>  
        public MainPage()          {              InitializeComponent();                // Wrap the itemList in a PagedCollectionView for paging functionality              PagedCollectionView itemListView = new PagedCollectionView(new Customers());              itemListView.GroupDescriptions.Add(new PropertyGroupDescription("FirstName"));                // Set the DataPager and ListBox to the same data source.              dataPager1.Source = itemListView;              dataGrid1.ItemsSource = itemListView;          }
    public class Customer      {          public int ID { get; set; }          public String FirstName { get; set; }          public String LastName { get; set; }          public String Address { get; set; }            public Customer() { }            public Customer(int id, String firstName, String lastName, String address)          {              this.ID = id;              this.FirstName = firstName;              this.LastName = lastName;              this.Address = address;          }      }      public class Customers : ObservableCollection<Customer>      {          public Customers()          {              Add(new Customer(1, "Michael", "Anderberg",                      "12 North Third Street, Apartment 45"));              Add(new Customer(2, "Chris", "Ashton",                      "34 West Fifth Street, Apartment 67"));              Add(new Customer(3, "Cassie", "Hicks",                      "56 East Seventh Street, Apartment 89"));              Add(new Customer(4, "Guido", "Pica",                      "78 South Ninth Street, Apartment 10"));                Add(new Customer(1, "Michael", "Anderberg",                      "12 North Third Street, Apartment 45"));              Add(new Customer(2, "Chris", "Ashton",                      "34 West Fifth Street, Apartment 67"));              Add(new Customer(3, "Cassie", "Hicks",                      "56 East Seventh Street, Apartment 89"));              Add(new Customer(4, "Guido", "Pica",                      "78 South Ninth Street, Apartment 10"));          }      }

Please feel free to let me know if you have any question.

Best Regards





No comments:

Post a Comment

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