Binding Text Fields

I linked text fields in winform from C # to a dataset. Whenever data is not checked so that the database, except for it, forces the focus to remain in the text field. How can I catch a validation error and tell the user about it (and release the focus)? The BindingSource OnDataError event does not fire.

+4
source share
2 answers

I had a similar problem. The focus remained in the text field, which was tied to some numeric database field, when the user changed the text in the text field and then deleted it so that the text property was an empty string. I solved this with something like:

textbox.DataBindings["Text"].NullValue = ""; 

He solved the problem for empty entries. I do not know if this will be useful in your case, but I am also interested in a more general solution.

There is also some related question about SO here:

DataBox related data: cannot exit

+2
source

Never rely solely on what β€œVisual studio has done for me” unless you fully understand what it is doing. I urge you to spend time and figure out how to do what you want to do on your own (this means code created without a developer). To get started, there are some events in TextBox that can help you. Start here:

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.validated.aspx

In particular, checked and verified events should be what you are looking for.

+1
source

All Articles