Category / Section
How to show the dropdown list when a key is pressed in the ComboBox cell in WinForms GridControl?
2 mins read
Dropdown list in grid
By default, the dropdown list is shown when the mouse is clicked on the dropdown button of the ComboBox cell. To show the dropdown list when any key is pressed in the ComboBox cell, the CurrentCell.ShowDropDown() method is used in the CurrentCellKeyPress event.
C#
this.gridControl1.CurrentCellKeyPress += new KeyPressEventHandler(gridControl1_CurrentCellKeyPress); void gridControl1_CurrentCellKeyPress(object sender, KeyPressEventArgs e) { //Checks whether the cell type is ComboBox or not. if (this.gridControl1[this.gridControl1.CurrentCellInfo.RowIndex, this.gridControl1.CurrentCellInfo.ColIndex].CellType == GridCellTypeName.ComboBox) { //Enables the show dropdown in the current cell. this.gridControl1.CurrentCell.ShowDropDown(); } }
VB
Private Me.gridControl1.CurrentCellKeyPress += New KeyPressEventHandler(AddressOf gridControl1_CurrentCellKeyPress) Private Sub gridControl1_CurrentCellKeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs) 'Checks whether the cell type is ComboBox or not. If Me.gridControl1(Me.gridControl1.CurrentCellInfo.RowIndex, Me.gridControl1.CurrentCellInfo.ColIndex).CellType Is GridCellTypeName.ComboBox Then 'Enables the show dropdown in the current cell. Me.gridControl1.CurrentCell.ShowDropDown() End If End Sub
After applying the properties, the Grid looks like the following screenshot.
Note:
Only the dropdown list values should be entered, otherwise, the dropdown is not shown.