Data Binding problem - DataTable not getting updated

G

Guest

I have a TextBox, textBox1, bound to a column in a DataTable. Any data the
user enters in the textBox1 is correctly used to update the DataTable. So if
the user enters "xyz", the corresponding field in the DataTable also contains
"xyz". However, when the user moves to another field, I want the data in the
textBox1 to be formatted, e.g. converted to upper case, and the formatted
data used to update the DataTable. I format the field in the
textBox1_LostFocus method and observe the field is formatted correctly on the
screen, so "xyz" changes to "XYZ". But after the user enters data in any
other field, textBox1 changes back to the original, unformatted value, "xyz".

It looks like my change in the LostFocus method did not cause the DataTable
to be updated with the new value. How do I make this happen?

Thanks,
John Ch.
 
A

Alex Feinman [MVP]

Default binding manager uses Validating event to update bindings. The
Validating event is thrown from inside OnLost focus as the very first thing.
After that the COntrol class raises Validated and LostFocus events. This
means that your table was already updated (or left unchanged) by the time
you got into your LostFocus handler.

Try using the Parse event of the Binding class:

Binding bnd = Textbox1.Bindings.Add("Text", myTable, "myColumn");
bnd.Parse = new ConvertEventHandler(myParseHandler);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top