开发者

Why the BindingManagerBase gets removed from the binding

I have a very strange case.... We have a user control with a text box, which is bound to a binding source.

BindingSource bindingSource = new BindingSource();
this.bindingSource.Add(this.viewMode);

this.textBox.DataBindings.Add(new Binding("EditValue", "Name", this.bindingSource, OnPropertyChanged));

We create an instance of this user control at runtime and add it to list, eg.

MyUserControl view = new MyUserControl();
ourViews.Add(view);

If we navigate on this view, it gets added to the Form:

MyUserControl view = 开发者_StackOverflow(MyUserControl)ourViews(0);
this.Controls.Add(view);

At this point (the first time we do this), the binding works well, the values gets updated in both directions.

Afterwards, some other view gets navigated and the view gets removed from the form:

this.Controls.Clear();
OtherUserControlView view = (OtherUserControl)ourViews(1);
this.Controls.Add(view);

And somewhen, our old view gets navigated again: MyUserControl view = (MyUserControl)ourViews(0); this.Controls.Add(view);

And now there is a problem. The binding does not update anymore. We recognized, that the BindingManagerBase of the binding instance is null (we didn't touch the binding since it was created) and the IsBinding property of the binding is set to false. So what caused this? And how we can activate the binding again?

Thanks for help, Eny


After enabling LayoutControl.UseLocalBindingContext the binding works fine for me. This property is hidden and cannot be set in the designer. You can set it in code.

I found this solution in the DevExpress-Supportcenter.


I'm doing a similar thing and I've found a different workaround. When you add the user control, back up its BindingContext somewhere (I have a "StackedControl" structure for this). When you remove it, restore it back. This seems to resolve the binding issues.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜