C# 如何在winforms中使用公共对象绑定?

C# 如何在winforms中使用公共对象绑定?,c#,winforms,data-binding,binding,C#,Winforms,Data Binding,Binding,我有一个公共字段对象: public class Field { public string Name { get; set; } public string oldName { get; set; } private object _Value = null; public object Value { get { return _Value; } set

我有一个公共字段对象:

public class Field
{
    public string Name { get; set; }
    public string oldName { get; set; }

    private object _Value = null;
    public object Value
    {
        get
        {
            return _Value;
        }
        set
        {
            _Value = value;
        }
    }

    private FieldType _fieldType = FieldType.Normal;
    public FieldType FieldType
    {
        get
        {
            return _fieldType;
        }
        set
        {
            _fieldType = value;
        }
    }
    private bool _isKey = false;
    public bool IsKey
    {
        get
        {
            return _isKey;
        }
        set
        {
            _isKey = value;
        }
    }
}
公共记录对象:

public class Record
{
    public string TableName{get;set;}
    pubilc FieldCollection _fieldcollection = new FieldCollection();
    public FieldCollection FieldCollection
    {
        get
        {
            return _fieldcollection;
        }
        set
        {
                _fieldcollection = value;
        }
    }
}
将数据库中的数据转换为记录对象,然后我想将记录数据绑定到控件,但它不起作用。 我想知道如何绑定数据,如:

textBox1.DataBindings.Add("Text", listBox1.DataSource , "BarDesc");

我认为您希望在设计时将BindingSource控件拖放到winform上

设置BindingSource的数据源属性>对象>记录类。然后设置BindingSource的DataMember

选择控件(例如Textbox),并将其数据绑定属性设置为bindingSource控件的DataMember


嗯,至少它应该为您指明了正确的方向。

我认为您希望在设计时将BindingSource控件拖放到winform上

设置BindingSource的数据源属性>对象>记录类。然后设置BindingSource的DataMember

选择控件(例如Textbox),并将其数据绑定属性设置为bindingSource控件的DataMember


嗯,至少它应该为您指明了正确的方向。

3ku但是,记录中有真实的字段名。FieldCollection[i]。FieldName!如何绑定DataMember:public Binding(string propertyName,Object dataSource,string DataMember)现在是我的主页时间了,但如果没有其他人加入,这里有一个更好的答案:3ku,但是记录中有真实的字段名。FieldCollection[I]。FieldName!如何绑定DataMember:public绑定(string propertyName、Object dataSource、string DataMember)现在是我的主时间,但如果没有其他人加入,这里有一个更好的答案: