Hey,
I'm faced with a problem that I cannot find a solution to.
My DGV is binded to an access db. It contains 2 columns (Date, Time), which are in the DateTime format. Everything else is a String. Now, on my CellValidating event, I go through each cell when creating a new row. What I made the program do is copy the date cell, and copy it into the time cell, which is before the time cell. As you can see on the following picture, the time cell is wrong... It should be as "11/07/2012 12:00 AM" instead of "01/01/0001 12:00 AM". Can anyone guide me in the right direction?
I'm faced with a problem that I cannot find a solution to.
My DGV is binded to an access db. It contains 2 columns (Date, Time), which are in the DateTime format. Everything else is a String. Now, on my CellValidating event, I go through each cell when creating a new row. What I made the program do is copy the date cell, and copy it into the time cell, which is before the time cell. As you can see on the following picture, the time cell is wrong... It should be as "11/07/2012 12:00 AM" instead of "01/01/0001 12:00 AM". Can anyone guide me in the right direction?
PHP:
Private Sub TimeLogDataGridView_CellValidating(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles TimeLogDataGridView.CellValidating
Dim Cell As DataGridViewCell = TimeLogDataGridView.Item(e.ColumnIndex, e.RowIndex)
' cell validation, to check if previous entry is OK
If Cell.IsInEditMode = True Then
Select Case TimeLogDataGridView.Columns(e.ColumnIndex).DataPropertyName
Case "Description"
If e.FormattedValue = "" Then
MsgBox("Enter a description.")
e.Cancel = True
Cell.Selected = True
Else
e.Cancel = False
End If
Case "currentDate"
If e.FormattedValue = "" Then
MsgBox("Enter a date.")
e.Cancel = True
Cell.Selected = True
Else
e.Cancel = False
Me.TimeLogDataGridView.Columns(2).DefaultCellStyle.Format = "g"
' this is for testing
Me.TimeLogDataGridView.CurrentRow.Cells(3).Value = TimeLogDataGridView.CurrentRow.Cells(0).Value.ToString
' this is screwed up
Me.TimeLogDataGridView.CurrentRow.Cells(2).Value = TimeLogDataGridView.CurrentRow.Cells(1).Value.ToString
' testing 2
Me.Label4.Text = TimeLogDataGridView.CurrentRow.Cells(2).Value.ToString
End If
Case "timeDate"
If e.FormattedValue <> "" Then
If IsDate(e.FormattedValue) = True Then
e.Cancel = False
Else
MsgBox("Enter a time.")
e.Cancel = True
Cell.Selected = True
End If
End If
End Select
End If
End Sub