Sloth Armstrong
Sloth Armstrong

Reputation: 1066

How can I force a TextBox's DataSource to update after a change in value through code?

I am binding a TextBox's text property to a field value in a DataTable as such:

With control.Item_Full_Description
     .DataBindings.Add("Text", mdtItemMstr, "Item_Full_Description", True)
End With

When I make changes to the TextBox manually they are detected and updated in the data source, thus a save to the database is accurate. If I make the change behind the scenes, however, the data source is not updated and a save to the database results in the old value being saved back. Here is how I am updating the TextBox in the code:

Item_Full_Description.Text = _mItem_mstr_c + " - " + Item_Description.Text + " - " + Unit_of_Measurement_UOM.Text

I am clearly missing a fundamental step to have this change reflected in the data source, however a search online is not proving to be useful. Maybe I am just uncertain of what to search so any advice or even guidance would be appreciated. Thanks.

Upvotes: 1

Views: 7277

Answers (1)

xspydr
xspydr

Reputation: 3060

Since you are updating the control from code you need to force the binding source to update.

Look into the BindingContext class... http://msdn.microsoft.com/en-us/library/system.windows.forms.control.bindingcontext%28v=vs.110%29.aspx

BindingContext([data source]).EndCurrentEdit()

Upvotes: 1

Related Questions