Thursday, April 26, 2007

Data Binding - Small tutorial about binding class member to a textbox

C# with its framework 2.0 introduces a new way of thinking with DataBinding. A lot of improvements have been done since the framework 1.0.

First of all, less code is required between component and business object. It's always possible to get deeper in the code; thence complex thing could still be done.

First of all, the way to bind simple object (instencied class) is easily done within less than 2 lines. Lets stay you want to bind the property Name of your Person class to a textbox.

Code would be: Person p = new Person("Henry");
this.txtName.DataBindings.Add(new Binding("Text", p, "Name"));

This code show a textbox that display "Henry" on it.

No comments: