How do you use common object binding in winforms?

柔情痞子 提交于 2020-01-02 09:38:25

问题


I have a Common Field Object:

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

a Common Record Object:

public class Record
{
    public string TableName{get;set;}
    pubilc FieldCollection _fieldcollection = new FieldCollection();
    public FieldCollection FieldCollection
    {
        get
        {
            return _fieldcollection;
        }
        set
        {
                _fieldcollection = value;
        }
    }
}

The Data from database to convert to Record Object,and then I want to Binding the Record Data to the Control,but it's not working. I want to know how can I Binding Data like:

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

回答1:


I think you want to drag and drop a BindingSource control onto your winform in Design-Time.

Set the BindingSource's DataSource property > Object > Record class. Then set the BindingSource's DataMember.

Select your control (eg Textbox) and set its DataBinding property to the bindingSource control's DataMember.

HTH, at least it should point you in the right direction.



来源:https://stackoverflow.com/questions/9187356/how-do-you-use-common-object-binding-in-winforms

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