绑定到选中的属性会弄乱ui,绑定到文本就可以了 [英] Binding to checked propert messes up ui, binding to text is fine

查看:72
本文介绍了绑定到选中的属性会弄乱ui,绑定到文本就可以了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:

我想我已经找到问题了.

I think i have found the problem.

所有影响绑定源的表单事件最后都具有以下内容:

All my forms events that affect the binding source have this in the end:

BndSource.ResetBindings(false);

如果我在CheckedChanged事件处理程序中评论此行,则该问题停止.但是为什么呢?

If i comment this line in my CheckedChanged event handler, the issue stops. But why?

我有一个非常奇怪的错误.

I have a very strange bug.

我有一个class属性:

I have a class property:

public SqlByte AutomaticFlag { get; set; }

我想使用复选框来方便显示此内容,因此在初始显示中我这样做:

I wanted to use checkbox to facilitate for showing this so in initial inding i do this:

        dtaAutomaticFlag.DataBindings.Add("Checked", BndSource, "AutomaticFlag", true);
        dtaAutomaticFlag.DataBindings[0].Format += (s, e) =>
        {
            if ((SqlByte)e.Value == 1)
            {
                e.Value = true;
            }
            else
            {
                e.Value = false;
            }
        };

问题是在迭代绑定源的所有记录期间,我的ui进行了一半更新,这意味着它不完整.见图片:

the problem is that during iteration through all records of the binding source my ui is half updated, meaning its not complete. See picture:

当我将上述绑定属性从选中状态更改为这样的文本时,很奇怪:

VERY strangely when i change the above binding property from checked to text like this:

dtaAutomaticFlag.DataBindings.Add("Text", BndSource, "AutomaticFlag", true);

用户界面还可以!!

图片:

推荐答案

我不确定这是否适用于这种特殊情况.但是,与其像您那样添加绑定:

I'm not sure if this applies to this particular situation. But rather than adding the binding as you did:

dtaAutomaticFlag.DataBindings.Add("Text", BndSource, "AutomaticFlag", true);

创建新"绑定实例是否有帮助?

Does creating a "new" binding instance help at all?

dtaAutomaticFlag.DataBindings.Add(new Binding("Text", BndSource, "AutomaticFlag", true));

这篇关于绑定到选中的属性会弄乱ui,绑定到文本就可以了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆