Why DataBinding doesn't work on second time around?

。_饼干妹妹 提交于 2020-01-11 08:59:52

问题


The error I got when I change the datasource of BindingSource

"databinding cannot find a row that is suitable for all bindings row that is suitable for all bindings"

        this.RemoveAllBindings(); // My work-around for the meantime

        bdsOrder.DataSource = _ds.Tables["orders"]; // errors here on second time around(first time is blank datatable, second time is when i open existing record, then it errors), dataset comes from Remoting
        bdsOrderDetail.DataSource = _ds.Tables["order_detail"];

        bdsPhoto.DataSource = _ds.Tables["order_photo"];
        bdnPhoto.BindingSource = bdsPhoto;

My Helper extension method work-around on perplexing "databinding cannot find a row..." error.

namespace MycComponentExtension
{
    public static class Helper
    {
        public static void RemoveAllBindings(this Form form)
        {
            RemoveAllBindings((Control)form);
        }

        private static void RemoveAllBindings(this Control root)
        {
            foreach (Control c in root.Controls)
            {
                if (c.Controls.Count > 0) RemoveAllBindings(c);

                root.DataBindings.Clear();
            }
        }

What's the meaning of "DataBinding cannot find a row..." error, if at all possible, can I eliminate my work-around on it?


回答1:


I have seen this error when no DataGridView is involved, but my data source was being updated from another thread (naughty!) and my binding had FormattingEnabled=false. Changing both of these seemed to fix the problem.



来源:https://stackoverflow.com/questions/680142/why-databinding-doesnt-work-on-second-time-around

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