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

Posted on 2007-10-09
Last Modified: 2013-12-17
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);
Question by:alexmcferron
    1 Comment
    LVL 96

    Accepted Solution

    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");


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now