473,326 Members | 2,061 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,326 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 12283
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.