I am trying to make a (very) simple Data Binding test, but it doesnt work as I expected... Say I have the following classes:
// this class represents some kind of data producer
public class DataSourceClass
{
public string Data { get; set; }
public DataSourceClass()
{ }
}
//this form holds the TextBox control as the Data consumer
public partial class DatabindingTestForm : Form
{
public DataSourceClass ds { get; set; }
public DatabindingTestForm()
{
InitializeComponent();
ds = new DataSourceClass();
textBox.DataBindings.Add("Text", ds, "Data");
}
private void checkBox_CheckedChanged(object sender, EventArgs e)
{
if (checkBox.Checked)
ds.Data = "CHECKED";
else
ds.Data = "NOT CHECKED";
}
}
I didnt add the designer code, but its there, and the form holds a TextBox object and a CheckBox object. As you can understand, I am trying to make the Textbox Text property change as the user checks \ unchecks the CheckBox. But this code doesnt update the TextBox Text property. can someone please explain me what am I missing?