Binding to checked propert messes up ui, binding to text is fine

醉酒当歌 提交于 2019-12-12 01:43:51

问题


UPDATE:

I think i have found the problem.

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

BndSource.ResetBindings(false);

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

I have a very strange bug.

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;
            }
        };

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);

the ui is ok!!

Picture:


回答1:


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));


来源:https://stackoverflow.com/questions/22692566/binding-to-checked-propert-messes-up-ui-binding-to-text-is-fine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!