I got the following error when trying to retrieve the data to the datetime picker control when clicking on the datagridvi开发者_运维百科ew row.
Dim i as byte
i = tblView.CurrentRow.Index
txtEnterDate.Text = tblView.Item(2, i).Value
txtPubYear.Text = tblView.Item(3, i).Value
The string was not recognized as a valid DateTime. There is an unknown word starting at index 0.
How can this be fixed?
It sounds as through there's a DateTimePicker involved, and there's a validated date already in Item(2,i)
Try this:
txtEnterDate.Text = DateTime.Parse(tblView.Item(2, i).Value);
The error you are getting suggests that the tblView Item collection has invalid data. Without seeing more code, its hard to tell what's going on. I would suggest setting a breakpoint on the offending line and using the Immediate window to determine why your array collection is empty.
精彩评论