Articles in this section
Category / Section

How to skip deleting the cell text of an exclusive ComboBox cell in WinForms GridControl?

2 mins read

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

 

Conclusion

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 forumsDirect-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)
Please sign in to leave a comment
Access denied
Access denied