473,383 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

simple databinding of a simple string to textbox

How do I bind a textbox to a simple string varaible with databinding?

I managed to do the binding but unfortnatedly the textvox does not get
updated when I change the string wich the textbox is bound to. I though
this automation is on of the purposes of the databinding ... ? What am
I doing wrong ?

See this little example code:

using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace DataBindingText2
{
public class Form1 : Form
{
private TextBox textBox1;
private Container components = null;
private Button button1;
private string mystr = "hallo";

public Form1()
{
InitializeComponent();
textBox1.DataBindings.Add(new Binding("Text",mystr,""));
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private void InitializeComponent()
{
this.textBox1 = new TextBox();
this.button1 = new Button();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new Point(8, 16);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new Size(408, 20);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "textBox1";
//
// button1
//
this.button1.Location = new Point(8, 48);
this.button1.Name = "button1";
this.button1.Size = new Size(408, 48);
this.button1.TabIndex = 1;
this.button1.Text = "change bound data";
this.button1.Click += new EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new Size(5, 13);
this.ClientSize = new Size(432, 118);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, EventArgs e)
{
mystr += mystr;
}
}
}

Nov 16 '05 #1
3 12303
A correction to my previous post.

"textBox1.DataBindings.Add(new Binding("Text",mystr,""));"

In VB.net, you can simply pass the Property name and the object as
parameters than as a new Binding object. Maybe, it is the same in C#.
Why don't you try

textBox1.DataBindings.Add("Text",mystr,"PropertyNa meOftheObject");

"PropertyNameOftheObject" is the datastore/member of the mystr object.

with regards,
J.V.Ravichandran
- http://www.geocities.com/
jvravichandran
- http://www.411asp.net/func/search?
qry=Ravichandran+J.V.&cob=aspnetpro
- http://www.southasianoutlook.com
- http://www.MSDNAA.Net
- http://www.csharphelp.com
- http://www.poetry.com/Publications/
display.asp?ID=P3966388&BN=999&PN=2
- Or, just search on "J.V.Ravichandran"
at http://www.Google.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #2
textBox1.DataBindings.Add(new Binding("Text",mystr,""));

In VB.net, you can simply pass the Property name and the object as
parameters than as a new Binding object. Maybe, it is the same in C#.
Why don't you try

textBox1.DataBindings.Add("Text",mystr);
with regards,
J.V.Ravichandran
- http://www.geocities.com/
jvravichandran
- http://www.411asp.net/func/search?
qry=Ravichandran+J.V.&cob=aspnetpro
- http://www.southasianoutlook.com
- http://www.MSDNAA.Net
- http://www.csharphelp.com
- http://www.poetry.com/Publications/
display.asp?ID=P3966388&BN=999&PN=2
- Or, just search on "J.V.Ravichandran"
at http://www.Google.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3

Ravichandran J.V. wrote:
"PropertyNameOftheObject" is the datastore/member of the mystr object.


Now that is exactly my problem. mystr is a string object, how can it
have datastore/member. What do I need to specify as
"PropertyNameOftheObject"

???

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: codymanix | last post by:
How can I bind a string-Array to a DataGrid? I've already set the MappingName in the to DataGridTablestyle to "Array", but the Grid seems to display only Garbage: Lenght| -------| 13 9 3 3
3
by: War Eagle | last post by:
I've been looking at .substring and .trim methods and I still have a question about extracting substrings from a textbox. Basically the textbox contains the full path to a file ... for example ...
0
by: Robert Ludig | last post by:
How do I bind a textbox to a simple string varaible with databinding? I managed to do the binding but unfortnatedly the textvox does not get updated when I change the string wich the textbox is...
1
by: AEgir Sveinsson | last post by:
Hi, I am having trouble with the databinding of my textboxes. They display correctly the data they are getting from the dataset but when I enter a new value, nothing seems to have changed and...
4
by: aroth | last post by:
I have a basic form with some dropdownlist controls that I would like to populate with items from a database. I keep getting the error "Cannot implicitly convert type...
5
by: TN Bella | last post by:
This sounds so simple...I want the textbox to automatically fill with today's date but how is that done? To lock it so the user can't edit it, I can use type="hidden" right? Thanks in advance for...
7
by: Justin Hoffman | last post by:
I am new to vb.net programming and am just exploring the way databinding works with Windows forms and am having trouble with some fairly basic customization of data entry. The form uses the...
0
by: KB | last post by:
I have a custom control that inherits from the standard textbox. Whenever the control loses focus (and reaches the validation events) it immediately writes to the datasource even when the text has...
2
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, is it possible to take just a plain textbox on my web page and databind it to my datacolumn value of a particular row in my datatable? thanks, rodchar
0
by: opedog | last post by:
I'm monkeying around with databinding, trying to learn all the ins and outs. I'm populating a label from one of my business objects properties which is a string, however, I want some formatting done...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.