[GcSpreadGrid] コンボボックス型セルの選択項目が変更されたときに発生するイベントはありますか?
対象製品
SPREAD for WPF 3.0J
詳細
GcSpreadGridコントロールには、コンボボックス型セルの選択項目が変更されたときに発生するイベントはありませんので、EditElementShowingイベントで編集用のコンボボックスコントロールを取得し、イベントをハンドルする必要があります。
◎サンプルコード(VB)
◎サンプルコード(C#)
◎サンプルコード(VB)
Public Sub New() InitializeComponent() ' コンボボックス型セルの設定 Dim combo As New GrapeCity.Windows.SpreadGrid.ComboBoxCellType() combo.Items.Add("日本語") combo.Items.Add("英語") combo.Items.Add("中国語") GcSpreadGrid1(1, 1).CellType = combo 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.ComboBoxCellType Then Dim gccmb As GrapeCity.Windows.SpreadGrid.Editors.GcComboBox = TryCast(GcSpreadGrid1.EditElement, GrapeCity.Windows.SpreadGrid.Editors.GcComboBox) If gccmb Is Nothing Then Return End If RemoveHandler gccmb.SelectionChanged, AddressOf comboEdit_SelectionChanged 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.GcComboBox Then Dim gccmb As GrapeCity.Windows.SpreadGrid.Editors.GcComboBox = TryCast(e.EditElement, GrapeCity.Windows.SpreadGrid.Editors.GcComboBox) If gccmb Is Nothing Then Return End If AddHandler gccmb.SelectionChanged, AddressOf comboEdit_SelectionChanged End If End Sub Private Sub comboEdit_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Console.WriteLine("comboEdit_SelectionChanged") End Sub
◎サンプルコード(C#)
public MainWindow() { InitializeComponent(); // コンボボックス型セルの設定 GrapeCity.Windows.SpreadGrid.ComboBoxCellType combo = new GrapeCity.Windows.SpreadGrid.ComboBoxCellType(); combo.Items.Add("aaa"); combo.Items.Add("bbb"); combo.Items.Add("ccc"); gcSpreadGrid1[1, 1].CellType = combo; // イベントの関連付け 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.ComboBoxCellType) { GrapeCity.Windows.SpreadGrid.Editors.GcComboBox gccmb = gcSpreadGrid1.EditElement as GrapeCity.Windows.SpreadGrid.Editors.GcComboBox; if (gccmb == null) { return; } gccmb.SelectionChanged -= comboEdit_SelectionChanged; } } // コンボボックスのイベント関連付け void gcSpreadGrid1_EditElementShowing(object sender, GrapeCity.Windows.SpreadGrid.EditElementShowingEventArgs e) { if (e.EditElement is GrapeCity.Windows.SpreadGrid.Editors.GcComboBox) { GrapeCity.Windows.SpreadGrid.Editors.GcComboBox gccmb = e.EditElement as GrapeCity.Windows.SpreadGrid.Editors.GcComboBox; if (gccmb == null) { return; } gccmb.SelectionChanged += comboEdit_SelectionChanged; } } private void comboEdit_SelectionChanged(object sender, SelectionChangedEventArgs e) { Console.WriteLine("comboEdit_SelectionChanged"); }