How can I update the value of a textbox to the anchor source using C #?

Consider this code:

txtLastModifyUserID.DataBindings.Add("Text", c_bsDataSetSource, "LastModifyUserID");
txtLastModifyUserID.Text = "1234";

      

Why can't the source be updated?

+3
c # winforms textbox bindingsource


source to share


3 answers


The DataBinding usually does not write a value until the control loses focus. Since you are updating the TextBox programmatically, the DataBinding does not know that something needs to be updated.

As you wrote your code, you will need to call the method WriteValue()

yourself (assuming there is only 1 data binding in the TextBox):



txtLastModifyUserID.DataBindings.Add("Text", c_bsDataSetSource, "LastModifyUserID");
txtLastModifyUserID.Text = "1234";
txtLastModifyUserID.DataBindings[0].WriteValue();

      

+11


source to share


I guess you should point OnPropertyChanged

to DataSourceUpdateMode

.



0


source to share


I think you're almost there. Just change the binding to "Value" instead of "Text". When you change this programmatically, as long as the data source is updated, the human eye should catch the update. Also specify DataSourceUpdateMode.OnPropertyChanged

.

0


source to share







All Articles
Loading...
X
Show
Funny
Dev
Pics