How do I bind textbox to myClass.property?

Discussion in 'C#' started by drichird, Feb 3, 2008.

  1. drichird

    drichird New Member

    Joined:
    Jan 15, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    I want to bind BOTH ways a textbox (textBox1) to rc1.RichText...

    When I first execute, textBox1 shows "richtext" as expected, but pressing
    button1 does not change textBox1 to "reset...". The bind only supports
    changing rc1.RichText whenever textBox1 changes, but not the other way.
    Am I missing something?

    Code:
    namespace WindowsApplication1
    {
    // simple form with one textbox and one button
        public partial class Form1 : Form
        {
            RichClass rc1 = new RichClass();
            public Form1()
            {
                InitializeComponent();
            }
            private void Form1_Load(object sender, EventArgs e)
            {
                textBox1.DataBindings.Add("Text", rc1, "RichText");
            }
            private void button1_Click(object sender, EventArgs e)
            {
                rc1.RichText = "reset richtext proprty";
            }
        }
        public class RichClass
        {
            private string richText;
            public RichClass()
            {
                richText = "richText";
            }
            public string RichText
            {
                get { return richText; }
                set { richText = value; }
            }
    
        }
    }
     
    Last edited by a moderator: Feb 3, 2008

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice