Articles in this section

How to get the index of the currently selected item in a ComboBox cell using WinForms GridControl?

The WinForms GridControl stores 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 only that point.

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();
}
}
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

The screenshots below illustrate the combobox in GridControl.

 

Showing GridControl with ComboBox


Figure
1: GridControl with ComboBox


Conclusion

I hope you enjoyed learning about how to get the index of the currently selected item in a ComboBox cell using WinForms GridControl.

You can refer to our WinForms GridControl feature tour page to know about its other groundbreaking feature representations and WinForms GridControl documentation, and how to quickly get started for configuration specifications.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied