選択したセルのフッタの背景色を変更する方法

文書番号 : 83363     文書種別 : 使用方法     登録日 : 2018/11/02     最終更新日 : 2018/11/02
文書を印刷する
対象製品
MultiRow for Windows Forms 10.0J
詳細
ダイナミックセルスタイルを使って独自に実装することで選択したセルのフッタの背景色を変更することができます。

[Visual Basic]
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    ' ダイナミックセルスタイルの作成
    Dim dynamicCellStyle As New GrapeCity.Win.MultiRow.DynamicCellStyle()
    dynamicCellStyle.ConditionHandler = New GrapeCity.Win.MultiRow.DynamicCellStyleConditionHandler(AddressOf CustomCondition)

    ' テンプレートの作成
    Dim template1 As GrapeCity.Win.MultiRow.Template = GrapeCity.Win.MultiRow.Template.CreateGridTemplate(2)
    Dim columnFooterSection As New GrapeCity.Win.MultiRow.ColumnFooterSection()
    columnFooterSection.BackColor = Color.White
    columnFooterSection.Cells.Add(New GrapeCity.Win.MultiRow.HeaderCell() With {.Location = template1.Row.Cells(0).Location, .Name = "footerCell1", .FlatStyle = FlatStyle.Flat, .Style = dynamicCellStyle})
    columnFooterSection.Cells.Add(New GrapeCity.Win.MultiRow.HeaderCell() With {.Location = template1.Row.Cells(1).Location, .Name = "footerCell2", .FlatStyle = FlatStyle.Flat, .Style = dynamicCellStyle})
    columnFooterSection.Height = columnFooterSection.Cells(0).Height
    template1.ColumnFooters.Add(columnFooterSection)

    ' MultiRowの設定
    GcMultiRow1.Template = template1
    GcMultiRow1.RowCount = 5
    GcMultiRow1.HeaderCellHighlightMode = GrapeCity.Win.MultiRow.HighlightMode.ContainedCells
End Sub

' 独自のダイナミックセルスタイル
Private Function CustomCondition(ByVal context As GrapeCity.Win.MultiRow.DynamicCellStyleContext) As GrapeCity.Win.MultiRow.CellStyle
    Dim cellStyle As New GrapeCity.Win.MultiRow.CellStyle
    If context.CellScope = GrapeCity.Win.MultiRow.CellScope.ColumnFooter Then
        If context.GcMultiRow.CurrentCellPosition.CellName = "textBoxCell1" Then
            If context.CellName = "footerCell1" Then
                cellStyle.BackColor = Color.LightBlue
            Else
                cellStyle.BackColor = Color.White
            End If
        ElseIf context.GcMultiRow.CurrentCellPosition.CellName = "textBoxCell2" Then
            If context.CellName = "footerCell2" Then
                cellStyle.BackColor = Color.LightBlue
            Else
                cellStyle.BackColor = Color.White
            End If
        End If
    End If
    Return cellStyle
End Function

[C#]
private void Form1_Load(object sender, EventArgs e)
{
    // ダイナミックセルスタイルの作成
    GrapeCity.Win.MultiRow.DynamicCellStyle dynamicCellStyle = new GrapeCity.Win.MultiRow.DynamicCellStyle();
    dynamicCellStyle.ConditionHandler = new GrapeCity.Win.MultiRow.DynamicCellStyleConditionHandler(CustomCondition);

    // テンプレートの作成
    GrapeCity.Win.MultiRow.Template template1 = GrapeCity.Win.MultiRow.Template.CreateGridTemplate(2);
    GrapeCity.Win.MultiRow.ColumnFooterSection columnFooterSection = new GrapeCity.Win.MultiRow.ColumnFooterSection();
    columnFooterSection.BackColor = Color.White;

    GrapeCity.Win.MultiRow.HeaderCell footer1 = new GrapeCity.Win.MultiRow.HeaderCell();
    footer1.Location = template1.Row.Cells[0].Location;
    footer1.Name = "footerCell1";
    footer1.FlatStyle = FlatStyle.Flat;
    footer1.Style = dynamicCellStyle;
    columnFooterSection.Cells.Add(footer1);

    GrapeCity.Win.MultiRow.HeaderCell footer2 = new GrapeCity.Win.MultiRow.HeaderCell();
    footer2.Location = template1.Row.Cells[1].Location;
    footer2.Name = "footerCell2";
    footer2.FlatStyle = FlatStyle.Flat;
    footer2.Style = dynamicCellStyle;
    columnFooterSection.Cells.Add(footer2);

    columnFooterSection.Height = columnFooterSection.Cells[0].Height;
    template1.ColumnFooters.Add(columnFooterSection);

    // MultiRowの設定
    gcMultiRow1.Template = template1;
    gcMultiRow1.RowCount = 5;
    gcMultiRow1.HeaderCellHighlightMode = GrapeCity.Win.MultiRow.HighlightMode.ContainedCells;
    
}

// 独自のダイナミックセルスタイル
private GrapeCity.Win.MultiRow.CellStyle CustomCondition(GrapeCity.Win.MultiRow.DynamicCellStyleContext context)
{
    GrapeCity.Win.MultiRow.CellStyle cellStyle = new GrapeCity.Win.MultiRow.CellStyle();
    if (context.CellScope== GrapeCity.Win.MultiRow.CellScope.ColumnFooter)
    {
        if (context.GcMultiRow.CurrentCellPosition.CellName == "textBoxCell1")
        {
            if (context.CellName == "footerCell1")
            {
                cellStyle.BackColor = Color.LightBlue;
            }else
            {
                cellStyle.BackColor = Color.White;
            }
        }
        else if (context.GcMultiRow.CurrentCellPosition.CellName == "textBoxCell2")
        {
            if (context.CellName == "footerCell2") {
                cellStyle.BackColor = Color.LightBlue;
            }else
            {
                cellStyle.BackColor = Color.White;
            }
        }
    }
    return cellStyle;
}