Hi,
Here I write the code for DateTime input validation of a DataGrid cell in
VB.Net.
Here is the Form Design. Now I code for the input
validation of Date Column and Time Column.
Now my code
is written under CellValidating Event.
Private Sub DataGridView1_CellValidating(sender As Object, e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles DataGridView1.CellValidating
Select Case e.ColumnIndex
Case 1,2
Me.DataGridView1.Rows(e.RowIndex).ErrorText
= ""
Dim
NewDate As Date
If
DataGridView1.Rows(e.RowIndex).IsNewRow Then Return
If
Not Date.TryParse(e.FormattedValue.ToString(),
NewDate) Then
e.Cancel = True
MsgBox("Enter correct DateTime format", MsgBoxStyle.Critical, "ERROR!")
DataGridView1.CurrentCell.Value = ""
End
If
End Select
End Sub
If there is any other better option,
Thank You,
Arka Gupta.

No comments:
Post a Comment