"Vlatko" <vl************@fer.hr> wrote in
news:uQ**************@TK2MSFTNGP11.phx.gbl:
I would like to write a class that has property, for example, MyText and
I want to be able to bind a Text property of a TextBox to my MyText
property. When I change the value of MyText property in my class that
change should be visible in binded control. How can I do this?
Just create a class with a property MyText and bind it to the
textbox as:
myTextBox.DataBindings.Add("Text", myObjectToBind, "MyText");
To be sure that changes are propagated, you have to define the
event MyTextChanged in the class with the property MyText as well. This
event can be a simple event:
public event EventHandler MyTextChanged;
Then when the value MyText should return changes, you simply raise
that event when there are subscribers:
private string _myText;
public event EventHandler MyTextChanged;
//..
public string MyText
{
get { return _myText; }
set
{
_myText=value;
if(MyTextChanged!=null)
{
MyTextChanged(this, New EventArgs());
}
}
}
the datbinding logic in the controls will bind to the Changed event if
they're binded to a property with the same name. When the event is fired,
they'll refresh themselves with the new value.
FB
--
Get LLBLGen Pro, the new O/R mapper for .NET:
http://www.llblgen.com