none
A qestion about the DataBindings in C# RRS feed

  • Question

  • Hey all,

    Please see the following small program:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    namespace WindowsFormsApplication4
    {
        public partial class Form1 : Form
        {
            public string Content { get; set; }
            
            public Form1()
            {
                InitializeComponent();

                txtContent.DataBindings.Add("Text", this, "Content");
            }

            private void button1_Click(object sender, EventArgs e)
            {
                Content = "Test";

                Console.WriteLine(txtContent.Text);       

           }   

        }
    }

    I bind "Text" property of txtContent with string Property "Content".

    If I click on the button, value "Test" will be assigned to property "Content", but the "Text" property doesn't change accordingly.

    Shouldn't the value "Test" assign to "Text" property automatically since it is binded with "Content" property?

    Can anyone give me some clue?

    Thanks in advance

    Saturday, July 28, 2012 7:12 AM

Answers