1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

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