G
Guest
Maybe someone can help me: How can I set the default of a DateTime field used
in a WinForms application to "Today".
This is what I tried:
- The underlying ADO DataColumn of data type DateTime has a default; but
this can only be set to a specific value; afaics, there is no expression
returning a DateTime value with the current date.
- In my WinForms application, when the user is on a new record, the value
of the corresponding DateTimePicker control is set to today like this:
if (((System.Data.DataRowView)this.bsCourses.Current).IsNew)
this.dtDate.Value = System.DateTime.Today;
where this.bsCourses is the current BindingSource and this.dtDate is the
DateTimePicker control (the code is excuted in the PositionChanged event of
the BindingSource). The DateTimePicker control properly accepts the current
date, but out of some reason, when the underlying DataRow is updated by means
of DataBinding, this date is not used, but is set to Null. Only when, in the
DateTimePicker control, the value is set explicitly by the user, everything
works as expected.
Any idea why or how this may otherwise be solved? Thanks for any hint.
in a WinForms application to "Today".
This is what I tried:
- The underlying ADO DataColumn of data type DateTime has a default; but
this can only be set to a specific value; afaics, there is no expression
returning a DateTime value with the current date.
- In my WinForms application, when the user is on a new record, the value
of the corresponding DateTimePicker control is set to today like this:
if (((System.Data.DataRowView)this.bsCourses.Current).IsNew)
this.dtDate.Value = System.DateTime.Today;
where this.bsCourses is the current BindingSource and this.dtDate is the
DateTimePicker control (the code is excuted in the PositionChanged event of
the BindingSource). The DateTimePicker control properly accepts the current
date, but out of some reason, when the underlying DataRow is updated by means
of DataBinding, this date is not used, but is set to Null. Only when, in the
DateTimePicker control, the value is set explicitly by the user, everything
works as expected.
Any idea why or how this may otherwise be solved? Thanks for any hint.