simmotech wrote:
Otis wrote:
The point is that the value you insert isn't valid for the field bound to the textbox. Winforms databinding them simply refuses to set the value and refuses to move on.
The textbox' .Text property is a string. You can't put a string into a datetime field, so it will never work. If you want databinding with a datetime field, bind the field to a datepicker.
It should work if the string is a 'valid' date time string but unfortunately you don't get to choose a Date format at design time for a TextBox. (Maybe the default is US format?)
You may need to manually create a Binding in code between the entity property and the control's Text property and then do some work when the Parse and Format events are fired to parse/set the string to a valid Datetime according to your required format.
See
ms-help://MS.VSCC.2003/MS.MSDNQTR.2005OCT.1033/cpref/html/frlrfsystemwindowsformsbindingclassparsetopic.htm
for an example (its for a Decimal number not a DateTime but the principal is the same)
Cheers
Simon
It's all OK now ...
Otis point me in the right direction and yes, the solution is what Simon wrote.
I created an control derived from text box that expose for binding the new property "DateValue" declared as Nullable (Of date), then I handle the Parse/Format events to return the right value when date it's not valid... something like this:
Private Sub _DataBinding_Format(ByVal sender As Object, ByVal e As System.Windows.Forms.ConvertEventArgs) Handles _DataBinding.Format
If e.DesiredType Is GetType(Nullable(Of Date)) Then
If e.Value Is System.DBNull.Value Then
e.Value = Nothing
End If
End If
End Sub
Private Sub _DataBinding_Parse(ByVal sender As Object, ByVal e As System.Windows.Forms.ConvertEventArgs) Handles _DataBinding.Parse
If e.DesiredType Is GetType(DateTime) Then
If Not IsDate(e.Value) Then
e.Value = Nothing
End If
End If
End Sub
Thanks
Matteo