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

AggregateFunctions() & CalculateAggregates not wokring on dynamic columns

1 Answer 111 Views
GridView
This is a migrated thread and some comments may be shown as answers.
chillfire
Top achievements
Rank 1
chillfire asked on 10 Jun 2014, 03:13 PM
Hi,

I am having a problem getting the column totals updating after a cell has been edited in a RadGridView.
The columns are all (bar one) generated at runtime in the code behind (not MVVM).

My XAML;

<telerik:RadGridView   Margin="6" 
                                                   AutoGenerateColumns="False"
   x:Name="dgProducts" 
                                                   RowIndicatorVisibility="Collapsed"
   SelectionUnit="Cell" 
                                                   IsSynchronizedWithCurrentItem="True"
   VerticalGridLinesBrush="#CCC"
   HorizontalGridLinesBrush="#CCC" 
                                                   CanUserInsertRows="False"
   CanUserResizeRows="False" 
                                                   CanUserDeleteRows="False"
   ItemsSource="{Binding PromotionVolumes}" 
                                                   RowHeight="25"
   IsFilteringAllowed="False" 
                                                   ShowGroupPanel="False"
   IsReadOnly="{Binding CurrentPromotion.IsReadOnly}" 
                                                   ScrollMode="RealTime"
                                                   Loaded="dgProducts_Loaded"
   telerik:StyleManager.Theme="Transparent" 
                                                   CanUserResizeColumns="True" 
                                                   ShowColumnFooters="True" 
                                                   CellEditEnded="dgProducts_CellEditEnded"
                                                   CanUserFreezeColumns="False"
                                                   >
                                <telerik:RadGridView.Columns>
                                    <telerik:GridViewDataColumn Header="Product Name"
                                        DataMemberBinding="{Binding Path=Product.DisplayName}"
                                       Width="170" IsReadOnly="True">
                                        <telerik:GridViewDataColumn.AggregateFunctions>
                                            <telerik:CountFunction Caption="Count: " />
                                        </telerik:GridViewDataColumn.AggregateFunctions>
                                    </telerik:GridViewDataColumn>
                                     
                                </telerik:RadGridView.Columns>


I generate the columns, one for each item in an array of data;

          var b = new Binding(string.Format("Measures[{0}].RawValue", i));
                   var column = new GridViewDataColumn
                       {
                           DisplayIndex = i + existingColumnCount,
                           UniqueName = (i + existingColumnCount).ToString(),
                           Header = measures[i].Name,
                           DataMemberBinding = new Binding(string.Format("Item[{0}].Value", i)),
                           MinWidth = 90,
                           IsReadOnlyBinding = new Binding(string.Format("Item[{0}].IsReadOnly", i)),
                           Tag = new Binding(string.Format("Item[{0}].RawValue", i))
                       };

                   if (measures[i].IsCalculate)
                   {
                       column.DataMemberBinding.Mode = BindingMode.TwoWay;
                       column.DataMemberBinding.UpdateSourceTrigger = UpdateSourceTrigger.Default;

                       var sf = new SumFunction() { Caption = "", SourceField = b.Path.Path, SourceFieldType = typeof(decimal), ResultFormatString = "{0:N0}" };
                       column.AggregateFunctions.Add(sf);
                       column.AggregateFunctions.Add(aggregate);
                   }

                   grid.Columns.Add(column);


When cell editing happens I call;

      private void dgProducts_CellEditEnded(object sender, GridViewCellEditEndedEventArgs e)
       {
           this.dgProducts.Items.CommitEdit();
           this.dgProducts.CalculateAggregates();
       }



Ordering the grid has no effect on the footer totals either.

I have seen other posts on the forums going back to 2009 and apparently this has been fixed?
What am I missing?


cheers
craig

1 Answer, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 11 Jun 2014, 08:22 AM
Hello Craig,

I suspect the problem is that the Aggregate functions cannot access the indexed property which you are bound to. You can check the Output window for BindingExpression errors which will indicate that indeed this is the problem. Furthermore, I cannot say anything with certainty without having the whole picture. Can you share the collection you are using with the indexer? 

Regards,
Nik
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
chillfire
Top achievements
Rank 1
Answers by
Nick
Telerik team
Share this question
or