How to skip deleting the cell text of an exclusive ComboBox cell in WinForms GridControl?
Skip the deleting cell in grid
When you set the ComboBox in a WinForms GridControl and assign the dropdown style as exclusive, the cell text is removed from the ComboBox cell while pressing delete key or backspace key.
Solution
To overcome this problem, you can use the CurrentCellKeyDown event to handle the Delete & BackSpace keys.
C#
// On Form load this.gridControl1.CurrentCellKeyDown += new KeyEventHandler(gridControl1_CurrentCellKeyDown); void gridControl1_CurrentCellKeyDown(object sender, KeyEventArgs e) { GridCurrentCell cc = this.gridControl1.CurrentCell; if (cc.Renderer.StyleInfo.CellType == "ComboBox" && cc.Renderer.StyleInfo.DropDownStyle == GridDropDownStyle.Exclusive) { // Pressing delete key or backspacekey if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Delete) { // not remove the cell content e.Handled = true; } } }
VB
‘On Form load AddHandler gridControl1.CurrentCellKeyDown, AddressOf gridControl1_CurrentCellKeyDown ' to perform action while pressing key Private Sub gridControl1_CurrentCellKeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Dim cc As GridCurrentCell = Me.gridControl1.CurrentCell If cc.Renderer.StyleInfo.CellType Is "ComboBox" AndAlso cc.Renderer.StyleInfo.DropDownStyle = GridDropDownStyle.Exclusive Then ' Pressing delete key or backspacekey If e.KeyCode = Keys.Back OrElse e.KeyCode = Keys.Delete Then ' not remove the cell content e.Handled = True End If End If End Sub
Samples:
C#: DropdownStyle.Exclusive_C#.zip
VB: DropdownStyle.Exclusive_VB.zip
I hope you enjoyed learning about how to skip deleting the cell text of an exclusive ComboBox cell in WinForms GridControl.
You can refer to our WinForms GridControl’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms GridControl documentation to understand how to present and manipulate data.
For current customers, you can check out our WinForms 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 WinForms GridControl and other WinForms components.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!