Updating the data of a data bound control.

This is an update to a previous post I made in another blog. It's to do with a problem in data binding thats not immediately obvious. Say you have a TextBox control and the Text property is bound to a field in some data structure.

If you set the TextBox.Text property through code like this.....

        Me.TextBox.Text = "Hello World"

...then the text in the TextBox is updated however the underlying data isn't. The TextBox displays one thing but the bound data stores something else and it's not that obvious there is a difference. 

You need to update the value right after setting the text using the following...

        Me.TextBox.DataBindings.Item("Text").WriteValue()

...this is a much simplier approach than the one I last posted.

Published Monday, July 17, 2006 6:15 PM by dsmyth

Comments

No Comments