[GcSpreadGrid] チェックボックス型セルをクリックしたときに発生するイベントはありますか?
対象製品
SPREAD for WPF 3.0J
詳細
GcSpreadGridコントロールには、チェックボックス型セルをクリックしたときに発生するイベントはありませんので、EditElementShowingイベントで編集用のチェックボックスコントロールを取得し、イベントをハンドルする必要があります。
◎サンプルコード(VB)
◎サンプルコード(C#)
◎サンプルコード(VB)
Public Sub New() InitializeComponent() ' チェックボックス型セルの設定 Dim ckbxcell As New GrapeCity.Windows.SpreadGrid.CheckBoxCellType() GcSpreadGrid1.Columns(0).CellType = ckbxcell End Sub ' チェックボックスのイベント関連付け解除 Private Sub GcSpreadGrid1_CellEditEnding(sender As Object, e As GrapeCity.Windows.SpreadGrid.SpreadCellEditEndingEventArgs) Handles GcSpreadGrid1.CellEditEnding If TypeOf GcSpreadGrid1(e.CellPosition).InheritedCellType Is GrapeCity.Windows.SpreadGrid.CheckBoxCellType Then Dim gcchk As GrapeCity.Windows.SpreadGrid.Editors.CheckBoxEditElement = TryCast(GcSpreadGrid1.EditElement, GrapeCity.Windows.SpreadGrid.Editors.CheckBoxEditElement) If gcchk Is Nothing Then Return End If RemoveHandler gcchk.Checked, AddressOf checkEdit_Checked RemoveHandler gcchk.Unchecked, AddressOf checkEdit_Unchecked End If End Sub ' チェックボックスのイベント関連付け Private Sub GcSpreadGrid1_EditElementShowing(sender As Object, e As GrapeCity.Windows.SpreadGrid.EditElementShowingEventArgs) Handles GcSpreadGrid1.EditElementShowing If TypeOf e.EditElement Is GrapeCity.Windows.SpreadGrid.Editors.CheckBoxEditElement Then Dim gcchk As GrapeCity.Windows.SpreadGrid.Editors.CheckBoxEditElement = TryCast(e.EditElement, GrapeCity.Windows.SpreadGrid.Editors.CheckBoxEditElement) If gcchk Is Nothing Then Return End If AddHandler gcchk.Checked, AddressOf checkEdit_Checked AddHandler gcchk.Unchecked, AddressOf checkEdit_Unchecked End If End Sub Private Sub checkEdit_Checked(sender As Object, e As RoutedEventArgs) Console.WriteLine("checkEdit_Checked") End Sub Private Sub checkEdit_Unchecked(sender As Object, e As RoutedEventArgs) Console.WriteLine("checkEdit_Unchecked") End Sub
◎サンプルコード(C#)
public MainWindow() { InitializeComponent(); // チェックボックス型セルの設定 GrapeCity.Windows.SpreadGrid.CheckBoxCellType ckbxcell = new GrapeCity.Windows.SpreadGrid.CheckBoxCellType(); gcSpreadGrid1.Columns[0].CellType = ckbxcell; // イベントの関連付け gcSpreadGrid1.CellEditEnding += new EventHandler(gcSpreadGrid1_CellEditEnding); gcSpreadGrid1.EditElementShowing += new EventHandler (gcSpreadGrid1_EditElementShowing); } // チェックボックスのイベント関連付け解除 void gcSpreadGrid1_CellEditEnding(object sender, GrapeCity.Windows.SpreadGrid.SpreadCellEditEndingEventArgs e) { if (gcSpreadGrid1[e.CellPosition].InheritedCellType is GrapeCity.Windows.SpreadGrid.CheckBoxCellType) { GrapeCity.Windows.SpreadGrid.Editors.CheckBoxEditElement gcchk = gcSpreadGrid1.EditElement as GrapeCity.Windows.SpreadGrid.Editors.CheckBoxEditElement; if (gcchk == null) { return; } gcchk.Checked -= checkEdit_Checked; gcchk.Unchecked -= checkEdit_Unchecked; } } // チェックボックスのイベント関連付け void gcSpreadGrid1_EditElementShowing(object sender, GrapeCity.Windows.SpreadGrid.EditElementShowingEventArgs e) { if (e.EditElement is GrapeCity.Windows.SpreadGrid.Editors.CheckBoxEditElement) { GrapeCity.Windows.SpreadGrid.Editors.CheckBoxEditElement gcchk = e.EditElement as GrapeCity.Windows.SpreadGrid.Editors.CheckBoxEditElement; if (gcchk == null) { return; } gcchk.Checked += checkEdit_Checked; gcchk.Unchecked += checkEdit_Unchecked; } } private void checkEdit_Checked(object sender, RoutedEventArgs e) { Console.WriteLine("checkEdit_Checked"); } private void checkEdit_Unchecked(object sender, RoutedEventArgs e) { Console.WriteLine("checkEdit_Unchecked"); }