Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 339
  • 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);
0
alexmac05
Asked:
alexmac05
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");

Bob
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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