简体   繁体   中英

How do you use common object binding in winforms?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM