DataBinding Validation Question...

  • Thread starter Thread starter Michael
  • Start date Start date
M

Michael

I've hooked up a TextBox's Text property with the property of a class.
However, when invalid data is entered, the data binding updates the object
immediately. Is there anyway to prevent this from happening? Or should I
just re-assign the value to the object directly in this case?
Thanks,



Michael
 
Michael,

Have you tried to hook up to the Validate event to prevent the value
from being written? You should be able to cancel the action when the
Validate event is fired and prevent the data binding.

Hope this helps.
 
Hi Michael,

Thank you for posting in the community! My name is Jeffrey, and I will be
assisting you on this issue.

Based on my understanding, you do simple databinding with textbox's Text
propety. But the changed value will immediately update the source
datasource without validate, so you want to validate the data before change
the datasource.

====================================================
Based on my experience, you may use TextBox.Validating event to hook into
the update process.

The Validating event takes a CancelEventArgs, which has one property:
Canel. You can check the updating value in the textbox and if the data is
invalid just set CancelEventArgs.Canel to true. This will prevent the
source from updating.

I have made a test project and it works well.

====================================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

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.
Have a nice day!!

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.
 
Hi Michael,

Does our reply resolve your problem?
If you still have any concern, please feel free to tell me, I will work
with you.

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.
 
Back
Top