Format input date in datagridview
A common problem faced in datagridview is how to format the date in the grid, here is a small way to do it:
Private Sub dataGridView1_CellParsing(ByVal sender As Object, ByVal e As DataGridViewCellParsingEventArgs)
If e.ColumnIndex = 0 Then
Dim [date] As String = DirectCast(e.Value, String)
Try
Dim month As String = [date].Substring(0, 2)
Dim day As String = [date].Substring(2, 2)
Dim year As String = [date].Substring(4, 4)
e.Value = New DateTime(Convert.ToInt32(year), Convert.ToInt32(month), Convert.ToInt32(day))
e.ParsingApplied = True
Catch ex As ExceptionMessageBox.Show(“parsing error!”)
End Try
End If
End Sub
Leave a Reply
You must be logged in to post a comment.