copy column and format

  • Thread starter Thread starter ahmeddc
  • Start date Start date
A

ahmeddc

Guest
hi

Use the following code to copy columns from a DataGridView to another
The code works well
If there is no empty cell in the Time or Date field

field 3 date with format "MM/dd/yyyy"

field 4 time format "hh:mm:ss tt"

field5 time format "hh:mm:ss tt"



But the problem may be blank fields for time or date then the code does not work
What is required is to transfer and copy data from the DataGridView 1 to the second and ignore the empty or null values date and time

For i = 0 To 5
FEMPLOYPRINTEND.DATAGID_PRINT.Columns.Add(DATAG_EMPLOYEDET.Columns(i).Clone)
Next

For ii = 0 To DATAG_EMPLOYEDET.Rows.Count - 1
Dim col0 = DATAG_EMPLOYEDET.Rows(ii).Cells(0).Value
Dim col1 = DATAG_EMPLOYEDET.Rows(ii).Cells(1).Value
Dim col2 = DATAG_EMPLOYEDET.Rows(ii).Cells(2).Value
Dim col3 = Format(DATAG_EMPLOYEDET.Rows(ii).Cells(3).Value, "MM/dd")
Dim col4 = Format(DATAG_EMPLOYEDET.Rows(ii).Cells(4).Value, "hh:mm tt")
Dim col5 = Format(DATAG_EMPLOYEDET.Rows(ii).Cells(5).Value, "hh:mm tt")

FEMPLOYPRINTEND.DATAGID_PRINT.Rows.Add(col0, col1, col2, col3, col4, col5)
Next




my try not work

For i = 0 To 5
FEMPLOYPRINTEND.DATAGID_PRINT.Columns.Add(DATAG_EMPLOYEDET.Columns(i).Clone)
Next

For ii = 0 To DATAG_EMPLOYEDET.Rows.Count - 1
Dim col0 = DATAG_EMPLOYEDET.Rows(ii).Cells(0).Value
Dim col1 = DATAG_EMPLOYEDET.Rows(ii).Cells(1).Value
Dim col2 = DATAG_EMPLOYEDET.Rows(ii).Cells(2).Value
Dim col3
Dim col4
If Not DATAG_EMPLOYEDET.Rows(ii).Cells(3).Value = Nothing Then
col3 = Format(DATAG_EMPLOYEDET.Rows(ii).Cells(3).Value, "MM/dd/yyyy")
Else
col3 = DATAG_EMPLOYEDET.Rows(ii).Cells(3).Value
End If
If Not DATAG_EMPLOYEDET.Rows(ii).Cells(4).Value = Nothing Then
col4 = Format(DATAG_EMPLOYEDET.Rows(ii).Cells(4).Value, "hh:mm:ss tt")
Else
col4 = DATAG_EMPLOYEDET.Rows(ii).Cells(4).Value
End If

Dim col5
If Not DATAG_EMPLOYEDET.Rows(ii).Cells(5).Value = Nothing Then
col5 = Format(DATAG_EMPLOYEDET.Rows(ii).Cells(5).Value, "hh:mm:ss tt")
Else
col5 = DATAG_EMPLOYEDET.Rows(ii).Cells(5).Value
End If


FEMPLOYPRINTEND.DATAGID_PRINT.Rows.Add(col0, col1, col2, col3, col4, col5)
Next

Continue reading...
 
Back
Top