Displaying Selection Count by Implementing Custom Summary Calculators

John Doe / Thursday, April 29, 2010

 

     The XamDataGrid has five built-in summary calculators – Sum, Average, Maximum, Minimum and Count. You can implement additional custom summary calculators by  inheriting the abstract SummaryCalculator class. You can see a full walkthrough here in o ur help. You can take advantage of this feature and implement functionality that is not related to the XamDataGrid’s data in an efficient way. For example, you can display the selected records or cells as a summary. The sample project for this blog post you can find here   .

Implementing this is fairly straightforward following the walkthrough

class SelectedRecordsCalculator : SummaryCalculator
{

        int _count = 0;

        public override void Aggregate(object dataValue, SummaryResult summaryResult, Record record)

        {

            if (record.IsSelected)

            {

                _count++;

            }

        }
        …

        public override void BeginCalculation(SummaryResult summaryResult)

        {

            _count = 0;

        }

        …
        public override object EndCalculation(SummaryResult summaryResult)

        {

            return _count;

        }
     }

 

Question : So, why not just get the count from the SelectedItems collection?

Answer : Because, you will not be able to get this: