[]
チェックボックス型セルはセルにチェックボックスを表示します。CheckBoxCellType クラスを使用して設定します。主な設定は次のとおりです。
!type=note
メモ:デザイナを使用した設定方法については、「チェックボックス型セルの設定」をご覧ください。
次の図のようにチェックボックスにテキストを表示する場合、Content プロパティを使用します。また TrueContent プロパティでチェックされたときのテキストを、FalseContent プロパティでチェックが外されたときのテキストを、IndeterminateContent プロパティでチェック状態が未確定のときのテキストを設定できます。

サンプルコード
CheckBoxCellType chk = new CheckBoxCellType();
chk.IndeterminateContent = "保留";
chk.TrueContent = "承認";
chk.FalseContent = "却下";
gcSpreadGrid1.Columns[0].CellType = chk;Dim chk As New CheckBoxCellType()
chk.IndeterminateContent = "保留"
chk.TrueContent = "承認"
chk.FalseContent = "却下"
GcSpreadGrid1.Columns(0).CellType = chk次の図のようにチェックボックスにテキスト以外の内容を表示する場合、ContentTemplate プロパティにデータ テンプレートを設定します。

サンプルコード
<sg:GcSpreadGrid>
<sg:GcSpreadGrid.Resources>
<DataTemplate x:Key="MyContent">
<Path Stretch="Uniform" Fill="#FF000000" Data="F1 M 173.354,624.292L 173.354,594.078L 188.461,609.185M 177.738,583.325C 163.457,583.325 151.88,594.902 151.88,609.185C 151.88,623.468 163.457,635.044 177.738,635.044C 192.021,635.044 203.598,623.468 203.598,609.185C 203.598,594.902 192.021,583.325 177.738,583.325 Z "/>
</DataTemplate>
</sg:GcSpreadGrid.Resources>
<sg:GcSpreadGrid.Columns>
<sg:Column>
<sg:Column.CellType>
<sg:CheckBoxCellType ContentTemplate="{StaticResource MyContent}"/>
</sg:Column.CellType>
</sg:Column>
</sg:GcSpreadGrid.Columns>
</sg:GcSpreadGrid>!type=note
メモ:CheckBoxCellType クラスの Content プロパティにコントロールなど WPF の UI 要素を設定することはできません。UI 要素を設定する場合は ContentTemplate プロパティを使用してください。
IsThreeState プロパティで設定します。
ユーザーがチェックボックスを操作したときの処理は WPF のコマンドに実装します。実行時、コマンド パラメータには操作されたチェックボックスのセルの情報を保存した CellCommandParameter が自動的に設定されます。そのため、開発者は CellCommandParameter の情報を使用してコマンドを実装できます。CellCommandParameter に設定される情報は次のとおりです。
CommandParameter の情報
プロパティ | 説明 |
|---|---|
チェックボックスが配置された領域 | |
セルの位置 | |
チェックボックス型セルの CustomCommandParameter プロパティが設定されている場合、その内容 |
次のサンプルコードは、チェックボックスをチェックした行のインデックスをポップアップで表示する処理を MyCheckCommand クラスに実装します。
サンプルコード
CheckBoxCellType chk = new CheckBoxCellType();
chk.Content = "承認";
chk.Command = new MyCheckCommand(gcSpreadGrid1);
gcSpreadGrid1.Columns[0].CellType = chk;public class MyCheckCommand : ICommand
{
private GcSpreadGrid _gcSpreadGrid;
public MyCheckCommand(GcSpreadGrid gcSpreadGrid)
{
this._gcSpreadGrid = gcSpreadGrid;
}
public bool CanExecute(object parameter)
{
return true;
}
public event EventHandler CanExecuteChanged;
public void OnCanExecuteChanged()
{
if (CanExecuteChanged != null)
CanExecuteChanged(this, EventArgs.Empty);
}
public void Execute(object parameter)
{
CellCommandParameter checkboxParameter = parameter as CellCommandParameter;
if((bool)this._gcSpreadGrid[checkboxParameter.CellPosition].Value)
MessageBox.Show("承認します。");
}
}Dim chk As New CheckBoxCellType()
chk.Content = "承認"
chk.Command = New MyCheckCommand(gcSpreadGrid1)
GcSpreadGrid1.Columns(0).CellType = chkPublic Class MyCheckCommand
Implements ICommand
Private _gcSpreadGrid As GcSpreadGrid
Public Sub New(gcSpreadGrid As GcSpreadGrid)
Me._gcSpreadGrid = gcSpreadGrid
End Sub
Public Function CanExecute(parameter As Object) As Boolean Implements ICommand.CanExecute
Return True
End Function
Public Event CanExecuteChanged As EventHandler Implements ICommand.CanExecuteChanged
Public Sub OnCanExecuteChanged()
RaiseEvent CanExecuteChanged(Me, EventArgs.Empty)
End Sub
Public Sub Execute(parameter As Object) Implements ICommand.Execute
Dim checkboxParameter As CellCommandParameter = DirectCast(parameter, CellCommandParameter)
If CBool(Me._gcSpreadGrid(checkboxParameter.CellPosition).Value) Then
MessageBox.Show("承認します。")
End If
End Sub
End Class