Category / Section
How to get the index of the currently selected item in a ComboBox cell?
1 min read
The Grid stores only the value in its style, or CellValue. When you want the selection index of the ComboBox, you can handle the CurrentCellCloseDropDown event and get the index from the list at that point.
C#
void gridControl1_CurrentCellCloseDropDown(object sender, Syncfusion.Windows.Forms.PopupClosedEventArgs e) { GridCurrentCell cc = this.gridControl1.CurrentCell; GridComboBoxCellRenderer cr = cc.Renderer as GridComboBoxCellRenderer; if (cr != null) { // Prints the ComboBox selected index. Console.WriteLine(cr.ListBoxPart.SelectedIndex); this.textBox1.Text = cr.ListBoxPart.SelectedIndex.ToString(); } }
VB
Private Sub gridControl1_CurrentCellCloseDropDown(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.PopupClosedEventArgs) Dim cc As GridCurrentCell = Me.gridControl1.CurrentCell Dim cr As GridComboBoxCellRenderer = TryCast(cc.Renderer, GridComboBoxCellRenderer) If cr IsNot Nothing Then ' Prints the ComboBox selected index. Console.WriteLine(cr.ListBoxPart.SelectedIndex) Me.textBox1.Text = cr.ListBoxPart.SelectedIndex.ToString() End If End Sub
Figure 1: GridControl with ComboBox
Sample Link:
C#: ComboBox Cell CS
VB: ComboBox Cell VB