M
Michael.Suarez
Let's suppose I have an instance of MyClass, which has the properties
MyText1 and MyText2, and sets the values of MyText1 and MyText2 to 'A'
and 'B' in it's constructor.
Let's also suppose I have a Form with textBox1, textBox2, btnShowValue,
and btnNew.
Let's also suppose I have this code.
//member of Form
MyClass MyObject;
//in Form Load Method:
{
MyObject = new MyClass();
textBox1.DataBindings.Add("Text", MyObject, "MyText1");
textBox2.DataBindings.Add("Text", MyObject, "MyText2");
}
//in btnShowValue Click Method
{
MessageBox.Show(MyObject.MyText1);
MessageBox.Show(MyObject.MyText2);
}
//in btnNew Click Method
{
MyObject = new MyClass();
}
If I were to run this program, I could start typing into Textbox1 and
Textbox2. Then if I were to click btnShowValue, I would see
MessageBoxes with the values of what I just typed, being as the
textboxes are bound to the properties of the object.
BUT, If I were to click btnNew, I would expect Textbox1 and Textbox2 to
revert to the default values 'A' and 'B'.
They do not. They stay the same. And clicking btnShowValues gives you
'A' and 'B' from now on, no matter what you type in the textboxes.
My question is WHY? What am I missing here?
and How do i alter this code so that it works the way I want it to?
MyText1 and MyText2, and sets the values of MyText1 and MyText2 to 'A'
and 'B' in it's constructor.
Let's also suppose I have a Form with textBox1, textBox2, btnShowValue,
and btnNew.
Let's also suppose I have this code.
//member of Form
MyClass MyObject;
//in Form Load Method:
{
MyObject = new MyClass();
textBox1.DataBindings.Add("Text", MyObject, "MyText1");
textBox2.DataBindings.Add("Text", MyObject, "MyText2");
}
//in btnShowValue Click Method
{
MessageBox.Show(MyObject.MyText1);
MessageBox.Show(MyObject.MyText2);
}
//in btnNew Click Method
{
MyObject = new MyClass();
}
If I were to run this program, I could start typing into Textbox1 and
Textbox2. Then if I were to click btnShowValue, I would see
MessageBoxes with the values of what I just typed, being as the
textboxes are bound to the properties of the object.
BUT, If I were to click btnNew, I would expect Textbox1 and Textbox2 to
revert to the default values 'A' and 'B'.
They do not. They stay the same. And clicking btnShowValues gives you
'A' and 'B' from now on, no matter what you type in the textboxes.
My question is WHY? What am I missing here?
and How do i alter this code so that it works the way I want it to?