Click here to Skip to main content
15,886,857 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This is the earlier stage of my edit feature. Help me please, what convert codes should i write in this kind of error?

error msg (Conversion from type 'TimeSpan' to type 'Date' is not valid.)

>datetimepicker3 and 4 are set to choose times

>me.datagridview1.row(i).cells(4).value() is the selected row,cell value and is in the datatype of time(7)

> my mission is to double click on the datagridview.row and force the value to show on specified textboxes and datetimepickers.

>but errors occurred codes lines in 11 & 12


Here's my codes with errors:
VB
Private Sub DataGridView1_CellDoubleClick(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick
     Dim i As Integer
     i = DataGridView1.SelectedCells(0).RowIndex
     Me.TextBox6.Text = Me.DataGridView1.Rows(i).Cells(6).Value.ToString()
     Me.TextBox8.Text = Me.DataGridView1.Rows(i).Cells(8).Value.ToString()
     Me.RichTextBox1.Text = Me.DataGridView1.Rows(i).Cells(7).Value.ToString()
     Me.TextBox9.Text = Me.DataGridView1.Rows(i).Cells(9).Value.ToString()
     Me.DateTimePicker1.Value = Me.DataGridView1.Rows(i).Cells(2).Value()
     Me.DateTimePicker2.Value = Me.DataGridView1.Rows(i).Cells(3).Value()
     'Me.DateTimePicker3.Value = Me.DataGridView1.Rows(i).Cells(4).Value()
     'Me.DateTimePicker4.Value = Me.DataGridView1.Rows(i).Cells(5).Value()

     If Me.DataGridView1.Rows(i).Cells(10).Value.ToString() = RadioButton1.Text Then
         Me.RadioButton1.Checked = True
     ElseIf Me.DataGridView1.Rows(i).Cells(10).Value.ToString() = RadioButton2.Text Then
         Me.RadioButton2.Checked = True
     ElseIf Me.DataGridView1.Rows(i).Cells(10).Value.ToString() = RadioButton3.Text Then
         Me.RadioButton3.Checked = True
     End If
 End Sub
Posted
Comments
I guess in the below lines ...

Me.DateTimePicker1.Value = Me.DataGridView1.Rows(i).Cells(2).Value()
Me.DateTimePicker2.Value = Me.DataGridView1.Rows(i).Cells(3).Value()

you need to convert Me.DataGridView1.Rows(i).Cells(2).Value() and Me.DataGridView1.Rows(i).Cells(3).Value() to DateTime and then assign to DateTimePicker as they are string values.
Sergey Alexandrovich Kryukov 3-Jun-13 23:18pm    
The real problem is how you ask a question. First of all, do you understand why such conversion would make no sense? Where is you logic? You got a message "cannot convert A to B". Do you fill like asking "how to convert A to B"?

Also, if System.DateTime and System.TimeSpan are involved, you should understand that we should see where these types are used. You can see it, but we cannot. We did not show what you put in your sell, so what's the point is asking such question?

Do you see the point?
—SA

1 solution

if Me.DataGridView1.Rows(i).Cells(5).Value is dbnull then
   msgbox(".....") 
else
   Me.DateTimePicker4.text = Me.DataGridView1.Rows(i).Cells(5).Value()
end if
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900