M
Mika M
Hi!
My Windows Form contains DateTimePicker to show date-type data from
DataTable. Because application need to be able to save "no date" ie.
NULL into database table, I solved it like way...
("dtpRepaired" is DateTimePicker-control)
dtpRepaired.Checked = Not IsDBNull(dt.Rows(cm.Position)("Repaired"))
If dtpRepaired.Checked Then
dtpRepaired.Value = Date.Parse(dt.Rows(cm.Position)("Repaired").ToString())
End If
Private Sub dtpRepaired_TextChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles dtpRepaired.TextChanged
dt.Rows(cm.Position)("Repaired") = IIf(dtpRepaired.Checked,
dtpRepaired.Value, DBNull.Value)
End Sub
....because I didn't succeeded to do this like this way bounding it
directly to the DataTable...
'dtpRepaired.DataBindings.Add(New Binding("Text", dt, "Repaired"))
This is almost working fine, but it occurs an error after cm.AddNew when
trying to change dtpRepaired-controls value or Checked-state.
Error message is: "There is no row at Position 5.". I understand this
why, but don't know how I could solve to make it possible to "add new"
and make it possible to edit dtpRepaired too without this problem. Any
succestions?
Is it really impossible to bound DateTimePicker-control to DataTable,
and make it possible to change date in DataTable to "NULL" ?
Hopefully you understand my problem with my poor english, I'm finnish
My Windows Form contains DateTimePicker to show date-type data from
DataTable. Because application need to be able to save "no date" ie.
NULL into database table, I solved it like way...
("dtpRepaired" is DateTimePicker-control)
dtpRepaired.Checked = Not IsDBNull(dt.Rows(cm.Position)("Repaired"))
If dtpRepaired.Checked Then
dtpRepaired.Value = Date.Parse(dt.Rows(cm.Position)("Repaired").ToString())
End If
Private Sub dtpRepaired_TextChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles dtpRepaired.TextChanged
dt.Rows(cm.Position)("Repaired") = IIf(dtpRepaired.Checked,
dtpRepaired.Value, DBNull.Value)
End Sub
....because I didn't succeeded to do this like this way bounding it
directly to the DataTable...
'dtpRepaired.DataBindings.Add(New Binding("Text", dt, "Repaired"))
This is almost working fine, but it occurs an error after cm.AddNew when
trying to change dtpRepaired-controls value or Checked-state.
Error message is: "There is no row at Position 5.". I understand this
why, but don't know how I could solve to make it possible to "add new"
and make it possible to edit dtpRepaired too without this problem. Any
succestions?
Is it really impossible to bound DateTimePicker-control to DataTable,
and make it possible to change date in DataTable to "NULL" ?
Hopefully you understand my problem with my poor english, I'm finnish