ICalculationインターフェースのコード
Imports GrapeCity.Win.MultiRow Public Class SumCalculation Implements ICalculation Public Function Calculate(ByVal context As GrapeCity.Win.MultiRow.CalculationContext) As Object Implements GrapeCity.Win.MultiRow.ICalculation.Calculate ' 表示されている行の合計の算出 Dim sumValue As Decimal = 0 Dim count As Integer = context.GcMultiRow.RowCount For i As Integer = 0 To count - 1 If context.GcMultiRow.Rows(i).Visible Then Dim temp As Decimal = 0 Decimal.TryParse(String.Concat(context.GcMultiRow(i, "textBoxCell1").Value), temp) sumValue += temp End If Next ' 戻り値の設定 Return sumValue End Function Public Function Clone() As Object Implements System.ICloneable.Clone Return New SumCalculation() End Function End Class
using GrapeCity.Win.MultiRow; public class SumCalculation : ICalculation { public object Calculate(CalculationContext context) { // 合計の算出 decimal sumValue = 0; int count = context.GcMultiRow.RowCount; for (int i = 0; i < count; i++) { if (context.GcMultiRow.Rows[i].Visible) { decimal temp = 0; decimal.TryParse(string.Concat(context.GcMultiRow[i, 0].Value), out temp); sumValue += temp; } } // 戻り値の設定 return sumValue; } public object Clone() { return new SumCalculation(); } }
コーディングによる設定
次のコードは、独自に作成した計算をサマリ型セルに設定して、その結果を表示します。
Imports GrapeCity.Win.MultiRow ' テンプレートの作成 Dim Template1 As Template = Template.CreateGridTemplate(2) ' 集計用セルの作成 Dim SummaryCell1 As New SummaryCell() SummaryCell1.Name = "SummaryCell1" SummaryCell1.Location = Template1.Row.Cells(0).Location SummaryCell1.Style.Format = "###,###" SummaryCell1.Calculation = New SumCalculation() ' フッタの設定 Dim ColumnFooterSection1 As New ColumnFooterSection() ColumnFooterSection1.Cells.Add(SummaryCell1) ColumnFooterSection1.Height = SummaryCell1.Height Template1.ColumnFooters.Add(ColumnFooterSection1) ' MultiRowの設定 GcMultiRow1.Template = Template1 GcMultiRow1.AllowUserToAddRows = False GcMultiRow1.RestoreValue = True GcMultiRow1.RowCount = 10 For i As Integer = 0 To GcMultiRow1.RowCount - 1 GcMultiRow1.SetValue(i, 0, i + 1) Next ' 1行目と3行目を非表示に設定 GcMultiRow1.Rows(0).Visible = False GcMultiRow1.Rows(2).Visible = False
using GrapeCity.Win.MultiRow; // テンプレートの作成 Template template1 = Template.CreateGridTemplate(2); // 集計用セルの作成 SummaryCell summaryCell1 = new SummaryCell(); summaryCell1.Name = "summaryCell1"; summaryCell1.Location = template1.Row.Cells[0].Location; summaryCell1.Style.Format = "###,###"; summaryCell1.Calculation = new SumCalculation(); // フッタの設定 ColumnFooterSection columnFooterSection1 = new ColumnFooterSection(); columnFooterSection1.Cells.Add(summaryCell1); columnFooterSection1.Height = summaryCell1.Height; template1.ColumnFooters.Add(columnFooterSection1); // MultiRowの設定 gcMultiRow1.Template = template1; gcMultiRow1.AllowUserToAddRows = false; gcMultiRow1.RestoreValue = true; gcMultiRow1.RowCount = 10; for(int i = 0; i < gcMultiRow1.RowCount; i++) { gcMultiRow1.SetValue(i, 0, i + 1); } // 1行目と3行目を非表示に設定 gcMultiRow1.Rows[0].Visible = false; gcMultiRow1.Rows[2].Visible = false;