• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 352
  • Last Modified:

Easy C#.NET databinding question (to bind a string to a textbox) - very simple

C#.NET Visual Studio 2005 DataBinding  simple question. I have a class called TextParms and it has a get method and a field that returns a string.  I am using data binding to bind this to a text box, but what should be the value of the third parameter to get this to work?
TextParms tp = new TextParms(200, "Casablanca", Color.Beige);
Inside of the TextParms class I have a string holding "Casablanca"   public string m_strText;
Inside of the TextParms class I have a get method to return this string:  public string getString()

In order to bind the value of the string which will be Casablanca to this text box, what is the value I should place in the third parameter for the databinding.add method?  I can get this to work with null in the value and the ToString() method returning the string, but I need to figure out another way.
 textBox1.DataBindings.Add("Text", tbList, null);
1 Solution
Bob LearnedCommented:
You would normally put the property/column name for the entity that is bound to the TextBox control.  You could set up a read-only property:

  public string Text
     get { return m_strText; }

And, add the binding:
  textBox1.DataBindings.Add("Text", tbList, "Text");

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now