【问题标题】:How do you use common object binding in winforms?如何在winforms中使用通用对象绑定?
【发布时间】:2012-02-29 12:52:03
【问题描述】:

我有一个公共字段对象:

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

【问题讨论】:

    标签: c# winforms data-binding binding


    【解决方案1】:

    我认为您想在设计时将 BindingSource 控件拖放到您的 winform 上。

    设置 BindingSource 的 DataSource 属性 > Object > Record 类。然后设置 BindingSource 的 DataMember。

    选择您的控件(例如文本框)并将其 DataBinding 属性设置为 bindingSource 控件的 DataMember。

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

    【讨论】:

    • 3ku 但是,Record.FieldCollection[i].FieldName 中的真实字段名!如何绑定DataMember: public Binding(string propertyName,Object dataSource, string dataMember)
    • 我现在该回家了,但如果没有其他人加入,这里有一个更好的答案:codeproject.com/Articles/15596/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-10
    • 2018-10-13
    • 2011-01-28
    • 2019-10-23
    • 2017-05-08
    • 2010-12-21
    • 2011-02-08
    相关资源
    最近更新 更多