■ GridControl 클래스의 CustomSummary 이벤트를 사용해 값이 비어있는 셀을 계수하는 방법을 보여준다.
▶ MainWindow.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
<Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid" Width="800" Height="600" Title="GridControl 클래스 : CustomSummary 이벤트를 사용해 값이 비어있는 셀 계수하기" FontFamily="나눔고딕코딩" FontSize="16"> <Grid> <dxg:GridControl x:Name="gridControl" CustomSummary="gridControl_CustomSummary" GroupCount="1"> <dxg:GridControl.Columns> <dxg:GridColumn FieldName="Text" /> <dxg:GridColumn FieldName="Number" /> </dxg:GridControl.Columns> <dxg:GridControl.SortInfo> <dxg:GridSortInfo FieldName="Text" /> </dxg:GridControl.SortInfo> <dxg:GridControl.GroupSummary> <dxg:GridSummaryItem FieldName="Number" SummaryType="Custom" DisplayFormat="Group empty cells count : {0}" /> </dxg:GridControl.GroupSummary> <dxg:GridControl.TotalSummary> <dxg:GridSummaryItem FieldName="Number" SummaryType="Custom" DisplayFormat="Total empty cells count : {0}"/> </dxg:GridControl.TotalSummary> <dxg:GridControl.View> <dxg:TableView x:Name="tableView" ShowTotalSummary="True" NavigationStyle="Cell" /> </dxg:GridControl.View> </dxg:GridControl> </Grid> </Window> |
▶ MainWindow.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
using System.Windows; using System.Collections.Generic; using DevExpress.Data; using DevExpress.Xpf.Grid; namespace TestProject { /// <summary> /// 메인 윈도우 /// </summary> public partial class MainWindow : Window { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 샘플 데이터 리스트 /// </summary> private List<SampleData> sampleDataList; /// <summary> /// 빈 셀 전체 수 /// </summary> private int emptyCellTotalCount = 0; /// <summary> /// 빈 셀 그룹 수 /// </summary> private int emptyCellGroupCount = 0; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainWindow() /// <summary> /// 생성자 /// </summary> public MainWindow() { InitializeComponent(); this.sampleDataList = new List<SampleData>(); for(int i = 0; i < 100; i++) { this.sampleDataList.Add(new SampleData() { Text = "group " + i % 10, Number = i }); if(i % 3 == 0) { this.sampleDataList[i].Number = null; } } this.gridControl.ItemsSource = this.sampleDataList; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 그리드 컨트롤 커스텀 요약 처리하기 - gridControl_CustomSummary(sender, e) /// <summary> /// 그리드 컨트롤 커스텀 요약 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void gridControl_CustomSummary(object sender, CustomSummaryEventArgs e) { if((e.Item as GridSummaryItem).FieldName != "Number") { return; } if(e.IsTotalSummary) { if(e.SummaryProcess == CustomSummaryProcess.Start) { this.emptyCellTotalCount = 0; } if(e.SummaryProcess == CustomSummaryProcess.Calculate) { int? fieldValue = (int?)e.FieldValue; if(!fieldValue.HasValue) { this.emptyCellTotalCount++; } e.TotalValue = this.emptyCellTotalCount; } } if(e.IsGroupSummary) { if(e.SummaryProcess == CustomSummaryProcess.Start) { this.emptyCellGroupCount = 0; } if(e.SummaryProcess == CustomSummaryProcess.Calculate) { int? fieldValue = (int?)e.FieldValue; if(!fieldValue.HasValue) { this.emptyCellGroupCount++; } e.TotalValue = this.emptyCellGroupCount; } } } #endregion } } |