数据源和显示成员 [英] Data Source and Display member

查看:112
本文介绍了数据源和显示成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!
我是C#的新手,并且出现此错误:

 System.Windows.Forms.TextBox'不包含'DataSource'的定义,也找不到扩展方法'DataSource'接受类型为'System.Windows.Forms.TextBox'的第一个参数(您是否缺少using指令或程序集引用?)



有人可以帮我吗?

解决方案

 私有 对象发​​送者,EventArgs e)
       {
           字符串 _strQuery = " ;
           _strQuery = " ;
           txtEmailAdres.DataSource =  this  .objBasa.Read(_strQuery).Tables [ 0 ].DefaultView;
           txtEmailAdresa.DisplayMember = " ;


       }


这是代码的一部分


TextBox 控件没有DataSource 属性或DataSource 方法,因此会引发上述错误.对于数据绑定TextBox ,我们必须使用
TextBoxDataBindings 收集属性,如下所示

 textBox1.DataBindings.Add _
   (新建绑定(" , ds," ))


在这里说明
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.databindings.aspx [ ^ ]

我认为此代码项目文章可能对您有所帮助
.NET Windows表单中的数据绑定概念 [ ^ ]

<textbox text="{Binding textBoxSource}" />



注意:要使此方法起作用,您需要将表单的DataContext设置为包含属性textBoxSourcetextBoxSource 的类,这必须是适当的.绑定不适用于字段或方法.


Hi!
I''m new in C# and I have this error:

System.Windows.Forms.TextBox' does not contain a definition for 'DataSource' and no extension method 'DataSource' accepting a first argument of type 'System.Windows.Forms.TextBox' could be found (are you missing a using directive or an assembly reference?)



Can somebody help me?

解决方案

private void frmLogin_Load(object sender, EventArgs e)
       {
           string _strQuery = "";
           _strQuery = "SELECT * FROM tblMembers";
           txtEmailAdres.DataSource = this.objBasa.Read(_strQuery).Tables[0].DefaultView;
           txtEmailAdresa.DisplayMember = "email";


       }


this is a part oft teh code


The TextBox control does not have the DataSource property or DataSource method, hence the above error is thrown. For data binding a TextBox we have to use
DataBindings collection property of TextBox as below

textBox1.DataBindings.Add _
   (New Binding("Text", ds, "customers.custName"))


which is explained here
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.databindings.aspx[^]

I think this Code Project article may be helpful to you
Data binding concepts in .NET windows forms[^]


I would assume that you are using WPF, and if using binding you are probably using MVVM, so want to define the binding in the XAML. For wpf what you would do is use binding:

<textbox text="{Binding textBoxSource}" />



Note: for this to work, you need to set the DataContext for the form to the class containing the property textBoxSource and textBoxSource must be a proeprty. Binding does not work on fields or methods.


这篇关于数据源和显示成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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