all groups > dotnet windows forms databinding > january 2005 >
You're in the

dotnet windows forms databinding

group:

DataSet still accepts invalid Date after Cancel during TextBox Validating


DataSet still accepts invalid Date after Cancel during TextBox Validating Don Fisher
1/12/2005 3:59:52 PM
dotnet windows forms databinding: Using VB.NET, I have a TextBox bound to a Dataset's DateTime Column. I've
added Parse and Format handlers to the binding, and have added code to the
TextBox Validating Event. During validating, the Date entered is checked for
its Year and, if too old, e.Cancel is set to True. However, even when
cancelled, the Parse Event still fires and the invalid but
correctly-formatted Date is still accepted into the DataSet Column. How do I
stop invalid Dates from reaching the DataSet? Thanks!

RE: DataSet still accepts invalid Date after Cancel during TextBox Validating v-jetan NO[at]SPAM online.microsoft.com (
1/13/2005 8:23:31 AM
Hi Don,

I will do some research on this issue, and reply to you ASAP, thanks for
your understanding.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
RE: DataSet still accepts invalid Date after Cancel during TextBox Validating v-jetan NO[at]SPAM online.microsoft.com (
1/14/2005 5:29:28 AM
Hi Don,

Sorry for letting you wait for so long.

Yes, I have reproduced out your issue, it seems that there is no easy way
to prevent or cancel the databinding process.

Currently, I think we should do the validating in Binding.Parse event. In
this event handler, just determine if the new value is valid, then reset it
to original value for invalid set value.(That is, just store its original
value and re-assign it to ConvertEventArgs.Value property)

Hope this helps.
===================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Re: DataSet still accepts invalid Date after Cancel during TextBox Validating Don Fisher
1/14/2005 9:12:15 AM
Hi Jeffrey,

Thanks for checking this out. As you suggested, I'll save the original value
and add code to the Parse event to do the replacing. The unavoidable problem
with this solution is that replacing the "bad" date with the original value
will still be treated as a "change" after calling EndCurrentEdit. I noticed
that this is not the case when a badly formatted date is entered. The date
is rejected by the dataset, causes an exception to be thrown in the Parse
event, and HasChanges is still False after calling EndCurrentEdit. Still, I
guess I can't argue that a "bad" but "valid format" date shouldn't be
treated as a "change" by the DataSet.

Don

Re: DataSet still accepts invalid Date after Cancel during TextBox Validating v-jetan NO[at]SPAM online.microsoft.com (
1/17/2005 5:39:12 AM
Hi Don,

Thanks for your feedback!

Yes, once any data touches the dataset, the dataset's state will be
modified. For this issue, we may explicitly call DataSet.AcceptChanges
method for restore operation. Then all the rows' state will return to
DataRowState.Unchanged.

Actually, I find that this feature has been added in Winform 2.0, please
refer to the link below:
"Improved Data Support"
http://msdn.microsoft.com/smartclient/understanding/windowsforms/2.0/feature
s/impdatasupport.aspx
"Numerous improvements have been made to simple property binding. With the
new improvements, you are now able to specify when bound controls push
their values to the back-end data source (on Validation, Property Change or
Never)."

Hope the information makes sense to you.
========================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Re: DataSet still accepts invalid Date after Cancel during TextBox Validating Don Fisher
1/18/2005 7:59:46 AM
Hi Jeffrey,

Thanks for the link to the Winform 2.0 Improved Data Support. Looks like
that feature will provide what I was looking for, so I'll keep it in mind
for my next project.

Don


Re: DataSet still accepts invalid Date after Cancel during TextBox Validating v-jetan NO[at]SPAM online.microsoft.com (
1/19/2005 5:49:15 AM
I am glad my reply makes sense to you. If you need further help, please
feel free to tell me, thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
AddThis Social Bookmark Button