作成日: 2022/03/11 最終更新日: 2022/03/30
文書種別
使用方法
詳細
ダイナミックセルを使用して、CurrentCellの背景色、前景色を変更することで実現することができます。
[Visual Basic]
[C#]
[Visual Basic]
Imports GrapeCity.Win.MultiRow Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' カレントセルの選択色を切り替えるためのダイナミックセルスタイルの作成 Dim style1 As DynamicCellStyle = New DynamicCellStyle() style1.ConditionHandler = New DynamicCellStyleConditionHandler(AddressOf CustomCondition) ' MultiRowの設定 Dim template1 As Template = Template.CreateGridTemplate(5) For i As Integer = 0 To template1.Row.Cells.Count - 2 template1.Row.Cells(i).Style = style1 Next GcMultiRow1.Template = template1 GcMultiRow1.RowCount = 5 End Sub Private Function CustomCondition(ByVal context As DynamicCellStyleContext) As CellStyle Dim cStyle As CellStyle = New CellStyle() If context.CellScope = CellScope.Row Then If context.RowIndex = context.GcMultiRow.CurrentCellPosition.RowIndex And context.CellIndex = context.GcMultiRow.CurrentCellPosition.CellIndex Then ' カレントセルの選択色を変更します。 cStyle.SelectionBackColor = SystemColors.Window cStyle.SelectionForeColor = SystemColors.WindowText End If End If Return cStyle End Function End Class
[C#]
using System;
using System.Drawing;
using System.Windows.Forms;
using GrapeCity.Win.MultiRow;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// カレントセルの選択色を切り替えるためのダイナミックセルスタイルの作成
DynamicCellStyle style1 = new DynamicCellStyle();
style1.ConditionHandler = new DynamicCellStyleConditionHandler(CustomCondition);
// MultiRowの設定
Template template1 = Template.CreateGridTemplate(5);
for (int i = 0; i < template1.Row.Cells.Count - 1; i++)
{
template1.Row.Cells[i].Style = style1;
}
gcMultiRow1.Template = template1;
gcMultiRow1.RowCount = 5;
}
private CellStyle CustomCondition(DynamicCellStyleContext context)
{
CellStyle cStyle = new CellStyle();
if (context.CellScope == CellScope.Row)
{
if (context.RowIndex == context.GcMultiRow.CurrentCellPosition.RowIndex && context.CellIndex == context.GcMultiRow.CurrentCellPosition.CellIndex)
{
// カレントセルの選択色を変更します。
cStyle.SelectionBackColor = SystemColors.Window;
cStyle.SelectionForeColor = SystemColors.WindowText;
}
}
return cStyle;
}
}
}