Click here to Skip to main content
15,914,924 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
Posted
Updated 26-Mar-12 13:21pm
v2
Comments
ZurdoDev 26-Mar-12 12:43pm    
Show the code.
Shahin Khorshidnia 26-Mar-12 19:24pm    
How is able to find the causes without checking to code?

C#
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
 
Share this answer
 
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
VB
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[^]
 
Share this answer
 
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.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900