PC Review

Thread Tools Rate Thread

simple databinding of a simple string to textbox

Robert Ludig
Posts: n/a
      4th Oct 2004
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()
textBox1.DataBindings.Add(new Binding("Text",mystr,""));
protected override void Dispose( bool disposing )
if( disposing )
if (components != null)
base.Dispose( disposing );
private void InitializeComponent()
this.textBox1 = new TextBox();
this.button1 = new Button();
// 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.Name = "Form1";
this.Text = "Form1";

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

Reply With Quote

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
databinding checkBoxList to a Dictionary<string, string> object Andy B Microsoft ASP .NET 0 21st Apr 2008 07:40 PM
databinding a textbox to a string Kyle Rowe Microsoft C# .NET 1 10th Feb 2005 09:49 AM
Re: simple databinding of a simple string to textbox Robert Ludig Microsoft C# .NET 0 5th Oct 2004 11:07 AM
simple databinding of a simple string to textbox Robert Ludig Microsoft C# .NET 3 4th Oct 2004 02:42 PM
Databinding Bible (REPOST FROM m.p.d.f.WindowsForms.Databinding) a Microsoft ADO .NET 1 16th Jul 2004 03:26 AM




All times are GMT +1. The time now is 08:14 PM.