選択できないセルも含めて選択行をハイライト表示できますか?

文書番号 : 37549     文書種別 : 使用方法     登録日 : 2014/08/27     最終更新日 : 2014/08/27
文書を印刷する
対象製品
MultiRow for Windows Forms 7.0J
詳細
SelectableプロパティがFalseに設定されているセルの背景にはSelectionBackColorが適用されませんので、行ヘッダのクリックで行全体を選択した時選択が無効のセルだけハイライト表示になりません。選択できないセルの背景も変更するには、CellPaintingイベントでセルの背景色を明示的に設定します。

下記のサンプルコードを参照してください。

[Visual Basic]
Imports GrapeCity.Win.MultiRow

Public Class Form1

  Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    ' MultiRowの初期設定
    Dim template1 As Template = Template.CreateGridTemplate(3)

    DirectCast(template1.Row.Cells(template1.Row.Cells.Count - 1), RowHeaderCell).SelectionMode = MultiRowSelectionMode.Row
    GcMultiRow1.Template = template1
    GcMultiRow1.RowCount = 5
    GcMultiRow1(0, 1).Selectable = False
  End Sub

  Private Sub GcMultiRow1_CellPainting(sender As Object, e As CellPaintingEventArgs) Handles GcMultiRow1.CellPainting
    ' 選択されている行のセルの背景色の設定
    If e.RowIndex > -1 Then
      Dim grid As GcMultiRow = sender
      If grid.Rows(e.RowIndex).Selected Then
        e.CellStyle.BackColor = e.CellStyle.SelectionBackColor
      End If
    End If
  End Sub

End Class

[C#]
using GrapeCity.Win.MultiRow;

namespace WindowsFormsApplication1
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
      // MultiRowの初期設定
      Template template1 = Template.CreateGridTemplate (3);

      ((RowHeaderCell)template1.Row.Cells[template1.Row.Cells.Count - 1]).SelectionMode = MultiRowSelectionMode.Row;
      gcMultiRow1.Template = template1;
      gcMultiRow1.RowCount = 5;
      gcMultiRow1[0, 1].Selectable = false;
    }

    private void gcMultiRow1_CellPainting(object sender, CellPaintingEventArgs e)
    {
      // 選択されている行のセルの背景色の設定
      if (e.RowIndex > -1)
      {
        GcMultiRow grid = sender as GcMultiRow;
        if (grid.Rows[e.RowIndex].Selected)
        {
          e.CellStyle.BackColor = e.CellStyle.SelectionBackColor;
        }
      }
    }
  }
}