The following example demonstrates how to use custom summaries to count the total number of empty cells in the specified grid column.
<Window x:Class="CustomSummary_EmptyCells.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
Title="Window1" Height="350" Width="450" >
<Grid>
<dxg:GridControl x:Name="grid" CustomSummary="grid_CustomSummary" GroupCount="1">
<dxg:GridControl.SortInfo>
<dxg:GridSortInfo FieldName="Text" />
</dxg:GridControl.SortInfo>
<dxg:GridControl.Columns>
<dxg:GridColumn FieldName="Text" />
<dxg:GridColumn FieldName="Number" />
</dxg:GridControl.Columns>
<dxg:GridControl.View>
<dxg:TableView x:Name="view" AutoWidth="True"
NavigationStyle="Cell" ShowTotalSummary="True"/>
</dxg:GridControl.View>
<dxg:GridControl.TotalSummary>
<dxg:GridSummaryItem FieldName="Number" SummaryType="Custom"
DisplayFormat="Total empty cells count: {0}"/>
</dxg:GridControl.TotalSummary>
<dxg:GridControl.GroupSummary>
<dxg:GridSummaryItem FieldName="Number" SummaryType="Custom"
DisplayFormat="Group empty cells count: {0}"/>
</dxg:GridControl.GroupSummary>
</dxg:GridControl>
</Grid>
</Window>
using System.Windows;
using System.Collections.Generic;
using DevExpress.Data;
using DevExpress.Xpf.Data;
using DevExpress.Xpf.Grid;
// ...
namespace CustomSummary_EmptyCells {
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window {
List<TestData> list;
Dictionary<int, bool> selectedValues = new Dictionary<int, bool>();
public Window1() {
InitializeComponent();
list = new List<TestData>();
for (int i = 0; i < 100; i++) {
list.Add(new TestData() { Text = "group " + i % 10, Number = i });
if (i % 3 == 0)
list[i].Number = null;
}
grid.ItemsSource = list;
}
int emptyCellsTotalCount = 0;
int emptyCellsGroupCount = 0;
void grid_CustomSummary(object sender, 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;
}
}
if (e.IsGroupSummary) {
if (e.SummaryProcess == CustomSummaryProcess.Start) {
emptyCellsGroupCount = 0;
}
if (e.SummaryProcess == CustomSummaryProcess.Calculate) {
int? val = (int?)e.FieldValue;
if (!val.HasValue)
emptyCellsGroupCount++;
e.TotalValue = emptyCellsGroupCount;
}
}
}
public class TestData {
public string Text { get; set; }
public int? Number { get; set; }
}
}
}
Imports Microsoft.VisualBasic
Imports System.Windows
Imports System.Collections.Generic
Imports DevExpress.Data
Imports DevExpress.Xpf.Data
Imports DevExpress.Xpf.Grid
' ...
Namespace CustomSummary_EmptyCells
''' <summary>
''' Interaction logic for Window1.xaml
''' </summary>
Partial Public Class Window1
Inherits Window
Private list As List(Of TestData)
Private selectedValues As New Dictionary(Of Integer, Boolean)()
Public Sub New()
InitializeComponent()
list = New List(Of TestData)()
For i As Integer = 0 To 99
list.Add(New TestData() With {.Text = "group " & i Mod 10, .Number = i})
If i Mod 3 = 0 Then
list(i).Number = Nothing
End If
Next i
grid.ItemsSource = list
End Sub
Private emptyCellsTotalCount As Integer = 0
Private emptyCellsGroupCount As Integer = 0
Private Sub grid_CustomSummary(ByVal sender As Object, ByVal e As CustomSummaryEventArgs)
If (CType(e.Item, GridSummaryItem)).FieldName <> "Number" Then
Return
End If
If e.IsTotalSummary Then
If e.SummaryProcess = CustomSummaryProcess.Start Then
emptyCellsTotalCount = 0
End If
If e.SummaryProcess = CustomSummaryProcess.Calculate Then
Dim val? As Integer = CType(e.FieldValue, Integer?)
If (Not val.HasValue) Then
emptyCellsTotalCount += 1
End If
e.TotalValue = emptyCellsTotalCount
End If
End If
If e.IsGroupSummary Then
If e.SummaryProcess = CustomSummaryProcess.Start Then
emptyCellsGroupCount = 0
End If
If e.SummaryProcess = CustomSummaryProcess.Calculate Then
Dim val? As Integer = CType(e.FieldValue, Integer?)
If (Not val.HasValue) Then
emptyCellsGroupCount += 1
End If
e.TotalValue = emptyCellsGroupCount
End If
End If
End Sub
Public Class TestData
Private privateText As String
Public Property Text() As String
Get
Return privateText
End Get
Set(ByVal value As String)
privateText = value
End Set
End Property
Private privateNumber? As Integer
Public Property Number() As Integer?
Get
Return privateNumber
End Get
Set(ByVal value? As Integer)
privateNumber = value
End Set
End Property
End Class
End Class
End Namespace