GroupDescriptors doesn't work on rebinding of the grid

2 posts, 0 answers
  1. Maulik Patel
    Maulik Patel avatar
    36 posts
    Member since:
    Mar 2010

    Posted 24 Sep 2010 Link to this post

    Hi there,

    I am using  GroupDescriptors for gruoping the rows in grid. I am facing a problem when removing the columns runtime from the grid. Here is steps what I do.

    1. Load the grid with some data on constructor itself.
    2. On click of "Refresh" button, 
        a. Remove the columns. 
        b. Add the same columns (loaded on first load) again. 
        c. Change the ItemsSource.
        d. Clear the group-desciptor and 
        e. Add the same group-desciptor again.

    If the above steps are follow, the aggregated function(s) is not working as expect. It shows the Count value (in this case) first time but it doesn't show any value if Refresh is clicked.

    Can anyone please look at the problem and provide the solution? Here is the code snippet.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using System.Windows.Data;
    using Telerik.Windows.Data;
    using Telerik.Windows.Controls;
      
    namespace SumFunction_RunTime
    {
        public partial class MainPage : UserControl
        {
            public MainPage()
            {
                InitializeComponent();
      
                //Get random data
                gridView.ItemsSource = Club.GetClubs(01);
      
                var newColumn = new CustomGridColumn() { 
                    DataMemberBinding = new Binding("StadiumCapacity"), 
                    UniqueName = "Capacity_RunTime",
                    Header = "Capacity column created runtime"
                };            
                CountFunction sumFunc = new CountFunction() { Caption = "Count" };
                newColumn.AggregateFunctions.Add(sumFunc);
                gridView.Columns.Add(newColumn);
      
                //Add Count Aggregated Function
                this.gridView.GroupDescriptors.Clear();
                Telerik.Windows.Data.GroupDescriptor oGD = new Telerik.Windows.Data.GroupDescriptor();
                oGD.Member = "Name";
                this.gridView.GroupDescriptors.Add(oGD);
            }
      
            private int clickNumber = 0;
      
            private void btnRefresh_Click(object sender, RoutedEventArgs e)
            {
                gridView.Columns.Clear();
      
      
                GridViewDataColumn column = new GridViewDataColumn();
                column.DataMemberBinding = new Binding("Name");
                column.Header = "Name";
                gridView.Columns.Add(column);
      
                column = new GridViewDataColumn();
                column.DataMemberBinding = new Binding("Established");
                column.Header = "Established";
                gridView.Columns.Add(column);
      
                column = new GridViewDataColumn();
                column.DataMemberBinding = new Binding("StadiumCapacity");
                column.Header = "StadiumCapacity";
                gridView.Columns.Add(column);
      
                //Get Random Data
                gridView.ItemsSource = Club.GetClubs(clickNumber);
                clickNumber ++;
                if (clickNumber >= 4)
                    clickNumber = 0;
                  
                //bool desciptorFound = false;
                //foreach (GroupDescriptor itemGD in this.gridView.GroupDescriptors)
                //{
                //    if (itemGD.Member == "Name")
                //        desciptorFound = true;
                //}
      
                this.gridView.GroupDescriptors.Clear();
                Telerik.Windows.Data.GroupDescriptor oGD = new Telerik.Windows.Data.GroupDescriptor();
                oGD.Member = "Name";
                this.gridView.GroupDescriptors.Add(oGD);            
                  
            }
        }
    }


    Regards,
    Maulik
  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 28 Sep 2010 Link to this post

    Hi Maulik Patel,


    In the constructor you add  an aggregate function such as :

    newColumn.AggregateFunctions.Add(sumFunc);

    So newColumn has an aggregate function and it displays it correctly.

    In the btnRefresh_Click method you have :
    gridView.Columns.Clear();

    as expected - this removes the newColumn with the aggregate function itselft.

    Logically after that - we do not have any aggregate functions and we do not see any aggregate results.

    As a solution:
     I
    n the body of the btnRefresh_Click method, please add an aggregate function to the newly created columns.

    Greetings,
    Pavel Pavlov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
Back to Top