开发者

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 th开发者_StackOverflow中文版e value I have just entered manually.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜