Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C# (http://www.go4expert.com/forums/c-sharp/)
-   -   How do I bind textbox to myClass.property? (http://www.go4expert.com/forums/i-bind-textbox-myclassproperty-t8630/)

drichird 3Feb2008 14:28

How do I bind textbox to myClass.property?
 
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; }
        }

    }
}



All times are GMT +5.5. The time now is 17:02.