作成日: 2026/06/24 最終更新日: 2026/06/24
文書種別
使用方法
詳細
コントロールには、コンボボックス型セルのテキストが編集されたときに発生するイベントがないため、EditElementShowingイベントで、編集用のコンボボックスコントロールを取得し、イベントをハンドルする必要があります。
◎サンプルコード(VB)
◎サンプルコード(VB)
Imports GrapeCity.Windows.SpreadGrid
Imports GrapeCity.Windows.SpreadGrid.Editors
Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs)
Dim c As New ComboBoxCellType()
c.Items.Add("AAA")
c.Items.Add("BBB")
c.Items.Add("CCC")
c.IsEditable = True
GcSpreadGrid1.Columns(0).CellType = c
End Sub
Private Sub GcSpreadGrid1_EditElementShowing(sender As Object, e As EditElementShowingEventArgs) Handles GcSpreadGrid1.EditElementShowing
If TypeOf GcSpreadGrid1.ActiveCell.InheritedCellType Is ComboBoxCellType Then
' コンボボックス型セルのイベントを関連付けます。
Dim gccmb As GcComboBox = TryCast(GcSpreadGrid1.EditElement, GcComboBox)
If Not gccmb Is Nothing Then
AddHandler gccmb.TextChanged, AddressOf comboEdit_TextChanged
End If
End If
End Sub
Private Sub GcSpreadGrid1_CellEditEnding(sender As Object, e As SpreadCellEditEndingEventArgs) Handles GcSpreadGrid1.CellEditEnding
If TypeOf GcSpreadGrid1.ActiveCell.InheritedCellType Is ComboBoxCellType Then
' コンボボックス型セルのイベントの関連付けを解除ます。
Dim gccmb As GcComboBox = TryCast(GcSpreadGrid1.EditElement, GcComboBox)
If Not gccmb Is Nothing Then
RemoveHandler gccmb.TextChanged, AddressOf comboEdit_TextChanged
End If
End If
End Sub
Private Sub comboEdit_TextChanged(sender As Object, e As RoutedEventArgs)
Console.WriteLine("comboEdit_TextChanged")
End Sub
◎サンプルコード(C#)using GrapeCity.Windows.SpreadGrid;
using GrapeCity.Windows.SpreadGrid.Editors;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
ComboBoxCellType c = new ComboBoxCellType();
c.Items.Add("AAA");
c.Items.Add("BBB");
c.Items.Add("CCC");
c.IsEditable = true;
GcSpreadGrid1.Columns[0].CellType = c;
}
private void GcSpreadGrid1_EditElementShowing(object sender, EditElementShowingEventArgs e)
{
if (GcSpreadGrid1.ActiveCell.InheritedCellType is ComboBoxCellType)
{
// コンボボックス型セルのイベントを関連付けます。
GcComboBox gccmb = GcSpreadGrid1.EditElement as GcComboBox;
if (gccmb != null)
{
gccmb.TextChanged += comboEdit_TextChanged;
}
}
}
private void GcSpreadGrid1_CellEditEnding(object sender, SpreadCellEditEndingEventArgs e)
{
if (GcSpreadGrid1.ActiveCell.InheritedCellType is GrapeCity.Windows.SpreadGrid.ComboBoxCellType)
{
// コンボボックス型セルのイベント関連付けを解除します。
GcComboBox gccmb = GcSpreadGrid1.EditElement as GcComboBox;
if (gccmb != null)
{
gccmb.TextChanged -= comboEdit_TextChanged;
}
}
}
private void comboEdit_TextChanged(object sender, RoutedEventArgs e)
{
Console.WriteLine("comboEdit_TextChanged");
}