2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
Restrict operation of delete and backspace keyTo restrict specific keys in Date time picker cells, you need to use CurrentCellKeyDown event and validate using key code. C# //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; void gridControl1_CurrentCellKeyDown(object sender, KeyEventArgs e) { //To restrict the operations of delete key. 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; } }
VB 'MonthCalendar celltype Me.gridControl1(1, 2).Text = "MonthCalendar" Me.gridControl1.ColWidths(2) = 100 Me.gridControl1(2, 2).CellType = GridCellTypeName.MonthCalendar 'Event Handler Me.gridControl1.CurrentCellKeyDown += 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 Sub
Screenshot
Samples: C#: RestrictKeys_CS VB: RestrictKeys_VB
|
2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.