PowerTools CalendarGrid for Windows Forms 1.0J
セルの値を集計する

CellValueChangedイベントを使用すると、セルの値が変更されたあとにイベントで処理が行えます。
次のコードでは、セルの値を集計する動作を実現しています。

Imports GrapeCity.Win.CalendarGrid
Imports InputManCell = GrapeCity.Win.CalendarGrid.InputMan

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    ' CalendarGcNumberCellTypeの設定をします。
    Dim GcNumberCellType1 As New InputManCell.CalendarGcNumberCellType()
    GcNumberCellType1.SideButtons.Clear()
    Dim GcNumberCellType2 As New InputManCell.CalendarGcNumberCellType()
    GcNumberCellType2.SideButtons.Clear()
    Dim GcNumberCellType3 As New InputManCell.CalendarGcNumberCellType()
    GcNumberCellType3.SideButtons.Clear()
    Dim GcNumberCellType4 As New InputManCell.CalendarGcNumberCellType()
    GcNumberCellType4.SideButtons.Clear()

    ' テンプレートの設定をします。
    Dim template As New CalendarTemplate()
    template.RowHeaderColumnCount = 1
    template.RowCount = 5

    template.RowHeader(1, 0).Value = "値1"
    template.RowHeader(2, 0).Value = "値2"
    template.RowHeader(3, 0).Value = "値3"
    template.RowHeader(4, 0).Value = "合計"

    template.ColumnHeader.Rows(0).Cells(0).DateFormat = "{DayOfWeek}"
    template.ColumnHeader.Columns(0).Width = 60
    template.Content.Rows(0).Cells(0).DateFormat = "{MonthDay}"
    template.Content.Rows(0).Cells(0).CellStyleName = "defaultStyle"
    template.Content.Rows(1).Cells(0).CellType = GcNumberCellType1
    template.Content.Rows(1).Cells(0).CellStyle.Alignment = CalendarGridContentAlignment.MiddleRight
    template.Content.Rows(1).Cells(0).Value = 0
    template.Content.Rows(2).Cells(0).CellStyleName = "defaultStyle"
    template.Content.Rows(2).Cells(0).CellType = GcNumberCellType2
    template.Content.Rows(2).Cells(0).CellStyle.Alignment = CalendarGridContentAlignment.MiddleRight
    template.Content.Rows(2).Cells(0).Value = 0
    template.Content.Rows(3).Cells(0).CellStyleName = "defaultStyle"
    template.Content.Rows(3).Cells(0).CellType = GcNumberCellType3
    template.Content.Rows(3).Cells(0).CellStyle.Alignment = CalendarGridContentAlignment.MiddleRight
    template.Content.Rows(3).Cells(0).Value = 0
    template.Content.Rows(4).Cells(0).CellStyleName = "defaultStyle"
    template.Content.Rows(4).Cells(0).CellType = GcNumberCellType4
    template.Content.Rows(4).Cells(0).CellStyle.Alignment = CalendarGridContentAlignment.MiddleRight
    template.Content.Rows(4).Cells(0).Enabled = False

    GcCalendarGrid1.Template = template
End Sub

Private Sub GcCalendarGrid1_CellValueChanged(sender As Object, e As CalendarCellEventArgs) Handles GcCalendarGrid1.CellValueChanged
    If e.CellPosition.RowIndex = 4 Then
        ' 合計値の設定時には計算処理をしない。
        Return
    End If

    ' 2行目-4行目の合計値を取得します。
    Dim sum As Integer = Integer.Parse(GcCalendarGrid1.Content(e.CellPosition.Date)(1, 0).Value.ToString()) +
        Integer.Parse(GcCalendarGrid1.Content(e.CellPosition.Date)(2, 0).Value.ToString()) +
        Integer.Parse(GcCalendarGrid1.Content(e.CellPosition.Date)(3, 0).Value.ToString())

    ' 合計値を5行目に設定します。
    GcCalendarGrid1.Content(e.CellPosition.Date)(4, 0).Value = sum
End Sub
using GrapeCity.Win.CalendarGrid;
using InputManCell = GrapeCity.Win.CalendarGrid.InputMan;

private void Form1_Load(object sender, EventArgs e)
{
    // CalendarGcNumberCellTypeの設定をします。
    var gcNumberCellType1 = new InputManCell.CalendarGcNumberCellType();
    gcNumberCellType1.SideButtons.Clear();
    var gcNumberCellType2 = new InputManCell.CalendarGcNumberCellType();
    gcNumberCellType2.SideButtons.Clear();
    var gcNumberCellType3 = new InputManCell.CalendarGcNumberCellType();
    gcNumberCellType3.SideButtons.Clear();
    var gcNumberCellType4 = new InputManCell.CalendarGcNumberCellType();
    gcNumberCellType4.SideButtons.Clear();

    // テンプレートの設定をします。
    var template = new CalendarTemplate();
    template.RowHeaderColumnCount = 1;
    template.RowCount = 5;

    template.RowHeader[1, 0].Value = "値1";
    template.RowHeader[2, 0].Value = "値2";
    template.RowHeader[3, 0].Value = "値3";
    template.RowHeader[4, 0].Value = "平均値";

    template.ColumnHeader.Rows[0].Cells[0].DateFormat = "{DayOfWeek}";
    template.ColumnHeader.Columns[0].Width = 60;
    template.Content.Rows[0].Cells[0].DateFormat = "{MonthDay}";
    template.Content.Rows[0].Cells[0].CellStyleName = "defaultStyle";
    template.Content.Rows[1].Cells[0].CellType = gcNumberCellType1;
    template.Content.Rows[1].Cells[0].CellStyle.Alignment = CalendarGridContentAlignment.MiddleRight;
    template.Content.Rows[1].Cells[0].Value = 0;
    template.Content.Rows[2].Cells[0].CellStyleName = "defaultStyle";
    template.Content.Rows[2].Cells[0].CellType = gcNumberCellType2;
    template.Content.Rows[2].Cells[0].CellStyle.Alignment = CalendarGridContentAlignment.MiddleRight;
    template.Content.Rows[2].Cells[0].Value = 0;
    template.Content.Rows[3].Cells[0].CellStyleName = "defaultStyle";
    template.Content.Rows[3].Cells[0].CellType = gcNumberCellType3;
    template.Content.Rows[3].Cells[0].CellStyle.Alignment = CalendarGridContentAlignment.MiddleRight;
    template.Content.Rows[3].Cells[0].Value = 0;
    template.Content.Rows[4].Cells[0].CellStyleName = "defaultStyle";
    template.Content.Rows[4].Cells[0].CellType = gcNumberCellType4;
    template.Content.Rows[4].Cells[0].CellStyle.Alignment = CalendarGridContentAlignment.MiddleRight;
    template.Content.Rows[4].Cells[0].Enabled = false;

    gcCalendarGrid1.Template = template;

    gcCalendarGrid1.CellValueChanged += gcCalendarGrid1_CellValueChanged;
}

private void gcCalendarGrid1_CellValueChanged(object sender, GrapeCity.Win.CalendarGrid.CalendarCellEventArgs e)
{
    if (e.CellPosition.RowIndex == 4)
    {
        // 合計値の設定時には計算処理をしない。         return;
    }

    // 2行目-4行目の合計値を取得します。
    int sum = int.Parse(gcCalendarGrid1.Content[e.CellPosition.Date][1, 0].Value.ToString()) +
        int.Parse(gcCalendarGrid1.Content[e.CellPosition.Date][2, 0].Value.ToString()) +
        int.Parse(gcCalendarGrid1.Content[e.CellPosition.Date][3, 0].Value.ToString());

    // 合計値を5行目に設定します。
    gcCalendarGrid1.Content[e.CellPosition.Date][4, 0].Value = sum;
}
参照

 

 


© 2014 GrapeCity inc. All rights reserved.