Restrict operation of delete and backspace key in WinForms Grid.
Restrict the operation of delete and backspace keys
To restrict specific keys in the Date time picker cells, you need to use the CurrentCellKeyDown event and validate using the key code.
//MonthCalendar celltype
this.gridControl1[1, 2].Text = "MonthCalendar";
this.gridControl1.ColWidths[2] = 100;
this.gridControl1[2, 2].CellType = GridCellTypeName.MonthCalendar;
//Event Handler
this.gridControl1.CurrentCellKeyDown += gridControl1_CurrentCellKeyDown;
private void gridControl1_CurrentCellKeyDown(object sender, KeyEventArgs e)
{
// Restrict delete key for MonthCalendar cells
int rowIndex = this.gridControl1.CurrentCell.RowIndex;
int columnIndex = this.gridControl1.CurrentCell.ColIndex;
if (this.gridControl1[rowIndex, columnIndex].CellType == GridCellTypeName.MonthCalendar
&& e.KeyCode == Keys.Delete)
{
e.Handled = true;
}
}'MonthCalendar celltype
Me.gridControl1(1, 2).Text = "MonthCalendar"
Me.gridControl1.ColWidths(2) = 100
Me.gridControl1(2, 2).CellType = GridCellTypeName.MonthCalendar
'Event Handler
AddHandler Me.gridControl1.CurrentCellKeyDown, AddressOf gridControl1_CurrentCellKeyDown
Private Sub gridControl1_CurrentCellKeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
'To restrict the operations of delete key.
Dim rowIndex As Integer = Me.gridControl1.CurrentCell.RowIndex
Dim columnIndex As Integer = Me.gridControl1.CurrentCell.ColIndex
If Me.gridControl1(rowIndex,columnIndex).CellType Is GridCellTypeName.MonthCalendar AndAlso (e.KeyCode = Keys.Delete) Then
e.Handled = True
End If
End SubThe
screenshot below shows the restriction of delete and backspace key operations
in the grid.

Conclusion
I hope you enjoyed learning about how to restrict operation of delete and backspace key in WinForms Grid.
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!