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

SumFunction on calculated column

1 Answer 124 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Justin Lee
Top achievements
Rank 1
Justin Lee asked on 17 Mar 2011, 05:41 PM
Hello,
I have a GridView bound to a list of objects.  The grid has 2 columns.  The first is bound to a property called Amount, and is editable.  The second is bound to a property called TotalAllocation and is readonly.  The TotalAllocation column has an aggregate function (sum).

<telerik:GridViewDataColumn Width="95" Header="Amount" 
     DataMemberBinding="{Binding Amount, Mode=TwoWay}" />
<telerik:GridViewDataColumn Width="135" Header="Total Allocated" 
     DataMemberBinding="{Binding TotalAllocated, Mode=OneWay}" DataFormatString="{}{0:c}">
     <telerik:GridViewDataColumn.AggregateFunctions>
          <telerik:SumFunction Caption="Sum: " ResultFormatString="{}{0:c}" 
               SourceField="TotalAllocated" />
     </telerik:GridViewDataColumn.AggregateFunctions>
</telerik:GridViewDataColumn>

The TotalAllocated property is a calculated property that uses the Amount property.  So in the Amount property, I raise propertychanged of both Amount and TotalAllocated.

private Decimal? _Amount = null;
public Decimal? Amount
 {
     get { return _Amount; }
     set
     {
          if (value != _Amount)
          {
               _Amount = value;
               NotifyPropertyChanged("Amount");
               NotifyPropertyChanged("TotalAllocated");
          }
     }
}

public Decimal ? TotalAllocated

 

{

 

 

     get 

     {

          return (_CostPerUnit.HasValue && _Amount.HasValue) ? _CostPerUnit * _Amount : null ;

 

     }

}

 


The TotalAllocated column works correctly : when I update the Amount column, it automatically updates the TotalAllocated column with the calculated value.  But the TotalAllocated Footer (sum function) does not update.  The sum is correct when the grid is first bound, but does NOT update as values update.

Let me know if there is a work around, or if I'm missing something.

Thanks,
Justin

1 Answer, 1 is accepted

Sort by
0
Justin Lee
Top achievements
Rank 1
answered on 17 Mar 2011, 07:59 PM
Sorry, you can ignore this post.  The sum updates once you select a different row or the grid looses focus.  When I wrote this post, I was working with 1 row in my grid, and was just clicking on a different cell within the row to commit the changes.  (so the sum wasn't updating because I was still in the same row)

Thanks,
Justin
Tags
GridView
Asked by
Justin Lee
Top achievements
Rank 1
Answers by
Justin Lee
Top achievements
Rank 1
Share this question
or