【问题标题】:Why DataBinding doesn't work on second time around?为什么 DataBinding 第二次不起作用?
【发布时间】:2009-03-25 03:37:55
【问题描述】:

我在更改BindingSource的数据源时遇到的错误

“数据绑定找不到适合所有绑定的行”

        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;

我的 Helper 扩展方法解决了令人困惑的“数据绑定找不到行...”错误。

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

“DataBinding 找不到行...”错误是什么意思,如果可能的话,我可以消除我的解决方法吗?

【问题讨论】:

    标签: c# winforms data-binding datasource bindingsource


    【解决方案1】:

    我在不涉及 DataGridView 时看到了这个错误,但是我的数据源正在从另一个线程更新(淘气!)并且我的绑定有 FormattingEnabled=false。更改这两个似乎可以解决问题。

    【讨论】:

    • 奇怪,FormattingEnabled=true 似乎神奇地避免了这种“数据绑定无法在列表中找到适合所有绑定的行”InvalidOperationException
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多