How to: Summarize Empty Cells
- 2 minutes to read
The following example demonstrates how to use custom summaries to count the total number of empty cells in a certain grid column.
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:CustomSummary"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:Grid="using:DevExpress.UI.Xaml.Grid"
x:Class="CustomSummary.MainPage"
mc:Ignorable="d">
<Grid>
<Grid:GridControl Name="grid"
AutoGenerateColumns="True"
ShowTotalSummary="True"
CustomSummary="grid_CustomSummary">
<Grid:GridControl.TotalSummary>
<Grid:GridSummaryItem FieldName="Number" SummaryType="Custom"
DisplayFormat="Total empty cells count: {0}"/>
</Grid:GridControl.TotalSummary>
</Grid:GridControl>
</Grid>
</Page>
using System.Collections.Generic;
using DevExpress.Data;
using DevExpress.UI.Xaml.Grid;
using Windows.UI.Xaml.Controls;
namespace CustomSummary {
public sealed partial class MainPage : Page {
int emptyCellsTotalCount = 0;
private void grid_CustomSummary(object sender, DevExpress.Data.CustomSummaryEventArgs e) {
if (((GridSummaryItem)e.Item).FieldName != "Number")
return;
if (e.IsTotalSummary) {
if (e.SummaryProcess == CustomSummaryProcess.Start) {
emptyCellsTotalCount = 0;
}
if (e.SummaryProcess == CustomSummaryProcess.Calculate) {
int? val = (int?)e.FieldValue;
if (!val.HasValue)
emptyCellsTotalCount++;
e.TotalValue = emptyCellsTotalCount;
}
}
}
}
}