views:

274

answers:

1

I'm learning to develop for compact framework and I've come across an issue that's bugging me.

I've bound a couple of textboxes to some properties (firstname & lastname of a person class) and have a menuitem which just does a showmessage of the full name, and it works fairly well except that the properties only get updated once the textbox losses focus. This means that if I change the firstname and press the show name menuitem, I get the old value of firstname.

Is there a way I can force an update of the databindings, or make it so that every time a character is changed in one of the textboxes the corresponding property is updated?

+1  A: 

If you do this, you risk putting bad data into your data object, but here is how to do this:

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

I again say that this is one of those things that sounds really easy, but will likely cause issues in the long run as you are 'binding' to data that has never been validated.

JasonRShaver
This does indeed work (thanks), how about the case where I just want to make sure that the textbox is synchronized with my object. The only way I can think of is to move focus away from the textbox (and perhaps back again), I'm guessing there is a cleaner way.
Alister