-
July 13th, 2012, 10:33 AM
#1
(VS 2010) DataGridView reading from cell
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?
PHP Code:
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
-
July 13th, 2012, 11:00 AM
#2
Re: (VS 2010) DataGridView reading from cell
Because you have a TIME/DATE field. Use # # around it in the format it expects. ddd. and the remainder as a fraction.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|