【チェックボックス型セル】 CheckChangedイベントを発生させる方法
対象製品
SPREAD for Windows Forms 5.0J
詳細
チェックボックス型セルでは編集中のエディタとしてFpCheckBoxクラスが使用されています。この場合、セルが編集モードに移行するタイミングで、FpCheckBoxクラスメンバであるCheckChangedイベントのハンドラ関連付けによって発生させることが出来ます。上記クラスの詳細については製品ヘルプをご参照ください。
◎サンプルコード(VB)
◎サンプルコード(C#)
◎サンプルコード(VB)
Imports FarPoint.Win
Imports FarPoint.Win.Spread.CellType
Dim chkcell As FpCheckBox
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
FpSpread1.ActiveSheet.Cells(0, 0).CellType = New CheckBoxCellType
End Sub
Private Sub FpSpread1_EditModeOn(ByVal sender As Object, ByVal e As System.EventArgs) Handles FpSpread1.EditModeOn
Dim iRow As Integer = FpSpread1.ActiveSheet.ActiveRowIndex
Dim iCol As Integer = FpSpread1.ActiveSheet.ActiveColumnIndex
If TypeOf (FpSpread1.ActiveSheet.GetCellType(iRow, iCol)) Is CheckBoxCellType Then
chkcell = CType(FpSpread1.EditingControl, FpCheckBox)
'イベントハンドラ関連付け
AddHandler chkcell.CheckChanged, AddressOf chkcell_CheckChanged
End If
End Sub
Private Sub FpSpread1_EditModeOff(ByVal sender As Object, ByVal e As System.EventArgs) Handles FpSpread1.EditModeOff
Dim iRow As Integer = FpSpread1.ActiveSheet.ActiveRowIndex
Dim iCol As Integer = FpSpread1.ActiveSheet.ActiveColumnIndex
If TypeOf (FpSpread1.ActiveSheet.GetCellType(iRow, iCol)) Is CheckBoxCellType Then
chkcell = CType(FpSpread1.EditingControl, FpCheckBox)
'イベントハンドラ関連付け解除
RemoveHandler chkcell.CheckChanged, AddressOf chkcell_CheckChanged
End If
End Sub
Private Sub chkcell_CheckChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Console.WriteLine(chkcell.CheckState.ToString())
End Sub
Imports FarPoint.Win.Spread.CellType
Dim chkcell As FpCheckBox
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
FpSpread1.ActiveSheet.Cells(0, 0).CellType = New CheckBoxCellType
End Sub
Private Sub FpSpread1_EditModeOn(ByVal sender As Object, ByVal e As System.EventArgs) Handles FpSpread1.EditModeOn
Dim iRow As Integer = FpSpread1.ActiveSheet.ActiveRowIndex
Dim iCol As Integer = FpSpread1.ActiveSheet.ActiveColumnIndex
If TypeOf (FpSpread1.ActiveSheet.GetCellType(iRow, iCol)) Is CheckBoxCellType Then
chkcell = CType(FpSpread1.EditingControl, FpCheckBox)
'イベントハンドラ関連付け
AddHandler chkcell.CheckChanged, AddressOf chkcell_CheckChanged
End If
End Sub
Private Sub FpSpread1_EditModeOff(ByVal sender As Object, ByVal e As System.EventArgs) Handles FpSpread1.EditModeOff
Dim iRow As Integer = FpSpread1.ActiveSheet.ActiveRowIndex
Dim iCol As Integer = FpSpread1.ActiveSheet.ActiveColumnIndex
If TypeOf (FpSpread1.ActiveSheet.GetCellType(iRow, iCol)) Is CheckBoxCellType Then
chkcell = CType(FpSpread1.EditingControl, FpCheckBox)
'イベントハンドラ関連付け解除
RemoveHandler chkcell.CheckChanged, AddressOf chkcell_CheckChanged
End If
End Sub
Private Sub chkcell_CheckChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Console.WriteLine(chkcell.CheckState.ToString())
End Sub
◎サンプルコード(C#)
using FarPoint.Win;
using FarPoint.Win.Spread.CellType;
FpCheckBox chkcell;
private void Form1_Load(object sender, System.EventArgs e)
{
fpSpread1.ActiveSheet.Cells[0, 0].CellType = new CheckBoxCellType();
}
private void fpSpread1_EditModeOn(object sender, System.EventArgs e)
{
int iRow = fpSpread1.ActiveSheet.ActiveRowIndex;
int iCol = fpSpread1.ActiveSheet.ActiveColumnIndex;
if (fpSpread1.ActiveSheet.GetCellType(iRow, iCol) is CheckBoxCellType)
{
chkcell = (FpCheckBox)fpSpread1.EditingControl;
//イベントハンドラ関連付け
chkcell.CheckChanged += new System.EventHandler(chkcell_CheckChanged);
}
}
private void fpSpread1_EditModeOff(object sender, System.EventArgs e)
{
int iRow = fpSpread1.ActiveSheet.ActiveRowIndex;
int iCol = fpSpread1.ActiveSheet.ActiveColumnIndex;
if (fpSpread1.ActiveSheet.GetCellType(iRow, iCol) is CheckBoxCellType)
{
chkcell = (FpCheckBox)fpSpread1.EditingControl;
//イベントハンドラ関連付け解除
chkcell.CheckChanged -= new System.EventHandler(chkcell_CheckChanged);
}
}
private void chkcell_CheckChanged(object sender, System.EventArgs e)
{
Console.WriteLine(chkcell.CheckState.ToString());
}
using FarPoint.Win.Spread.CellType;
FpCheckBox chkcell;
private void Form1_Load(object sender, System.EventArgs e)
{
fpSpread1.ActiveSheet.Cells[0, 0].CellType = new CheckBoxCellType();
}
private void fpSpread1_EditModeOn(object sender, System.EventArgs e)
{
int iRow = fpSpread1.ActiveSheet.ActiveRowIndex;
int iCol = fpSpread1.ActiveSheet.ActiveColumnIndex;
if (fpSpread1.ActiveSheet.GetCellType(iRow, iCol) is CheckBoxCellType)
{
chkcell = (FpCheckBox)fpSpread1.EditingControl;
//イベントハンドラ関連付け
chkcell.CheckChanged += new System.EventHandler(chkcell_CheckChanged);
}
}
private void fpSpread1_EditModeOff(object sender, System.EventArgs e)
{
int iRow = fpSpread1.ActiveSheet.ActiveRowIndex;
int iCol = fpSpread1.ActiveSheet.ActiveColumnIndex;
if (fpSpread1.ActiveSheet.GetCellType(iRow, iCol) is CheckBoxCellType)
{
chkcell = (FpCheckBox)fpSpread1.EditingControl;
//イベントハンドラ関連付け解除
chkcell.CheckChanged -= new System.EventHandler(chkcell_CheckChanged);
}
}
private void chkcell_CheckChanged(object sender, System.EventArgs e)
{
Console.WriteLine(chkcell.CheckState.ToString());
}
関連情報
キーワード
「チェックボックス型セル」