如何使用公共对象中的WinForms约束力? [英] How do you use common object binding in winforms?

查看:107
本文介绍了如何使用公共对象中的WinForms约束力?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个共同的字段对象:

 公共类字段
{
    公共字符串名称{;组; }
    公共字符串使用oldName {搞定;组; }    私有对象_Value = NULL;
    公共对象值
    {
        得到
        {
            返回_Value;
        }
        组
        {
            _Value =价值;
        }
    }    私人的FieldType _fieldType = FieldType.Normal;
    公众的FieldType的FieldType
    {
        得到
        {
            返回_fieldType;
        }
        组
        {
            _fieldType =价值;
        }
    }
    私人布尔_isKey = FALSE;
    公共BOOL IsKey
    {
        得到
        {
            返回_isKey;
        }
        组
        {
            _isKey =价值;
        }
    }
}

一个共同记录对象:

 公共类记录
{
    公共字符串表名{获得;设置;}
    pubilc FieldCollection _fieldcollection =新FieldCollection();
    公共FieldCollection FieldCollection
    {
        得到
        {
            返回_fieldcollection;
        }
        组
        {
                _fieldcollection =价值;
        }
    }
}

从数据库中的数据转换为记录对象,然后我想绑定的记录数据到控制,但它不工作。
我想知道我怎么可以绑定数据,如:

  textBox1.DataBindings.Add(文本,listBox1.DataSource,BarDesc);


解决方案

我觉得你要拖放的BindingSource控制到在设计时的WinForm的

设置的BindingSource的DataSource属性>对象> Record类。然后设置的BindingSource的数据成员。

选择您的控制(如文本框)和它的数据绑定属性设置到BindingSource控件的数据成员。

HTH,至少它应该指向你在正确的方向。

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.

这篇关于如何使用公共对象中的WinForms约束力?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆