特定のセルを選択するときRowDefaultCellStyleではなくCell.Styleの設定を優先させるには?
対象製品
MultiRow for Windows Forms 10.0J
詳細
テンプレートで特定のセルのStyle.ForeColorプロパティと、RowDefaultCellStyleのSelectionForeColorプロパティを同時に使用してセルの前景色を設定した時、通常セルの選択時ではSelectionForeColorプロパティの設定が優先されます。
特定のセル側の設定を優先して表示したい場合は、CellEnterイベントで色を再設定する方法が考えられます。
例えば、次のサンプルコードは、セルが選択された時でも、セルの元の前景色を維持する方法を示しています。
[Visual Basic]
[C#]
特定のセル側の設定を優先して表示したい場合は、CellEnterイベントで色を再設定する方法が考えられます。
例えば、次のサンプルコードは、セルが選択された時でも、セルの元の前景色を維持する方法を示しています。
[Visual Basic]
Private Sub GcMultiRow1_CellEnter(ByVal sender As System.Object, ByVal e As GrapeCity.Win.MultiRow.CellEventArgs) Handles GcMultiRow1.CellEnter Dim newcell As GrapeCity.Win.MultiRow.Cell newcell = GcMultiRow1.Rows(e.RowIndex).Cells(e.CellIndex) ' セルの前景色がRedの場合、選択時の前景色もRedに設定する If (newcell.Style.ForeColor = Color.Red) Then newcell.Style.SelectionForeColor = newcell.Style.ForeColor End If End Sub
[C#]
private void gcMultiRow1_CellEnter(object sender, GrapeCity.Win.MultiRow.CellEventArgs e) { GrapeCity.Win.MultiRow.Cell newcell = default(GrapeCity.Win.MultiRow.Cell); newcell = gcMultiRow1.Rows[e.RowIndex].Cells[e.CellIndex]; // セルの前景色がRedの場合、選択時の前景色もRedに設定する if (newcell.Style.ForeColor == Color.Red) { newcell.Style.SelectionForeColor = newcell.Style.ForeColor; } }