473,804 Members | 3,091 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Componen tModel;
using System.Drawing;
using System.Windows. Forms;
namespace DataBindingText 2
{
public class Form1 : Form
{
private TextBox textBox1;
private Container components = null;
private Button button1;
private string mystr = "hallo";

public Form1()
{
InitializeCompo nent();
textBox1.DataBi ndings.Add(new Binding("Text", mystr,""));
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
}
private void InitializeCompo nent()
{
this.textBox1 = new TextBox();
this.button1 = new Button();
this.SuspendLay out();
//
// textBox1
//
this.textBox1.L ocation = new Point(8, 16);
this.textBox1.N ame = "textBox1";
this.textBox1.S ize = new Size(408, 20);
this.textBox1.T abIndex = 0;
this.textBox1.T ext = "textBox1";
//
// button1
//
this.button1.Lo cation = new Point(8, 48);
this.button1.Na me = "button1";
this.button1.Si ze = new Size(408, 48);
this.button1.Ta bIndex = 1;
this.button1.Te xt = "change bound data";
this.button1.Cl ick += new EventHandler(th is.button1_Clic k);
//
// Form1
//
this.AutoScaleB aseSize = new Size(5, 13);
this.ClientSize = new Size(432, 118);
this.Controls.A dd(this.button1 );
this.Controls.A dd(this.textBox 1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayo ut(false);

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

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

"textBox1.DataB indings.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.DataBi ndings.Add("Tex t",mystr,"Prope rtyNameOftheObj ect");

"PropertyNameOf theObject" is the datastore/member of the mystr object.

with regards,
J.V.Ravichandra n
- http://www.geocities.com/
jvravichandran
- http://www.411asp.net/func/search?
qry=Ravichandra n+J.V.&cob=aspn etpro
- 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.Ravichandr an"
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.DataBi ndings.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.DataBi ndings.Add("Tex t",mystr);
with regards,
J.V.Ravichandra n
- http://www.geocities.com/
jvravichandran
- http://www.411asp.net/func/search?
qry=Ravichandra n+J.V.&cob=aspn etpro
- 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.Ravichandr an"
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:
"PropertyNameO ftheObject" 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
"PropertyNameOf theObject"

???

Nov 16 '05 #4

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

Similar topics

1
2449
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
2657
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 C:\testfile.txt or ... C:\download\temp\dlls\testfile.dll I want to be able to extract the file name from this textbox (and put it in a string) when I click a button. Can someone illustrate how to write this line of code?
0
413
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 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;
1
1361
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 the following if statement never gets true. if (dataSet1.HasChanges(DataRowState.Modified)) {
4
1169
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 'System.Data.SqlClient.SqlDataReader' to 'bugreq.SqlDataReader'". The code from 'codebehind' is posted below. using System; using System.Collections; using System.ComponentModel; using System.Data;
5
1353
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 the help <asp:textbox id="RptDate" runat="server" Width="200px"> *** Sent via Devdex http://www.devdex.com *** Don't just participate in USENET...get rewarded for it!
7
2732
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 SqlDataAdapter and SqlDataset and loads a very simple table, with both text and integer fields. If a textbox is bound to an integer source where the current value is a valid integer, say 9, I can type in the textbox 'rubbish' and move to another...
0
1103
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 not changed. The standard textbox does not do this and will not write to a datasource unless the text has been changed. What could I be doing wrong. I have checked that my control is not making any changes to the text property or any other...
2
1039
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
1137
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 on the string first. I got this working using the binding's Format event. But, I want to go one step further. Instead of using the Format event, I'm trying to set the FormatString and FormatInfo properties to make the databinding go through the...
0
9569
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10318
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10302
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7608
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5503
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2975
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.