Update data bindings when TextBox changes, but does not lose focus

I am involved in development for compact frameworks, and I ran into a problem that is pushing me.

I have attached a couple of text fields to some properties (first and last name of the person class) and have a menu item that just shows the full name and works quite well, except that the properties are updated only once the focus is the loss of text fields. This means that if I change the first name and click on the show name menuitem button, I will get the old firstname value.

Is there a way to force the data binding to be updated, or to make it possible that every time a character is changed in one of the text fields, the corresponding property is updated?

+3
source share
2 answers

If you do this, you risk putting bad data in your data object, but here's how to do it:

In your method, MyTextBox.DataBinding.Add()use this overload with OnPropertyChanged for DataSourceUpdateMode instead of the standard OnValidate

Again, I say that this is one of those things that sounds very simple, but is likely to cause problems in the end, as you are “tied” to data that has never been verified.

+6
source

Just call the ValidateChildren () form in the code on the save button

+5
source

Source: https://habr.com/ru/post/1709429/


All Articles