Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF - Temporarily Stop Data Binding (databinding)

I have a textbox that is bound (oneway) to a datatable that updates a couple of time a second. So the textbox value continually reflects changes in datatable. When I enter the textbox to manually set a value, the binding causes the value to continually be overwritten. How do I stop this? When I have entered a value (textbox lost focus) I want the textbox to return to display the bound value and not the value I have just entered manually.

like image 820
Adam Avatar asked Aug 17 '26 23:08

Adam


2 Answers

I had the same problem and I solve it by

  1. With the BindingNavigator, I set it to null

    bdNavProduct.BindingSource =null;

  2. With other textbox control, datagridview, I clear the DataBinding

         txtProductID.DataBindings.Clear();
         txtProductName.DataBindings.Clear();
         txtQuantity.DataBindings.Clear();
         txtUnitPrice.DataBindings.Clear();
         dgvProduct.DataBindings.Clear();
    

Tony

like image 111
Tony Avatar answered Aug 19 '26 18:08

Tony


You could attach to the text input event and cancel the binding and then reapply it on the lost focus event.

I think however you need to consider why you are displaying your bound value in a text box at all? Would it not be more appropriate to have an uneditable Textblock displaying your database information with the editable Textbox separate for the optional user input.

While what you are asking is doable using the Textbox event I mentioned, it seems like it would be confusing from a user perspective.

like image 26
Lozzey Avatar answered Aug 19 '26 18:08

Lozzey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!