dotnetmonitor.com |
|
|||||||||||
| /*******************************************************************
* Setup (using the Visual Studio Form designer): * * Add a DataGridView to the Form (dataGridView1) * Add 3 TextBoxes to the Form (textBox1, textBox2 and textBox3) * Add the code below to the Form.Load event ******************************************************************/
/******************************************************************* * Create a list of customers. The list instance is named blc. * Note: Customer has properties ID, Name and Rate ******************************************************************/
BindingList<Customer> blc = new BindingList<Customer>();
blc.Add(new Customer(0, "Mr. Zero", 10.0M)); blc.Add(new Customer(1, "Mrs. One", 15.0M)); blc.Add(new Customer(2, "Dr. Two", 20.0M));
/******************************************************************* * Bind the DataGridView to the list of Customers using Complex * binding (customer business type is shown above). ******************************************************************/
this.dataGridView1.DataSource = blc;
/******************************************************************* * Bind the business object list to the TextBoxes. This uses simple * binding of the form "binding to a property on an item in a list". ******************************************************************/
this.textBox1.DataBindings.Add("Text", blc, "ID", true); this.textBox2.DataBindings.Add("Text", blc, "Name", true); this.textBox3.DataBindings.Add("Text", blc, "Rate", true); |
|||||||||||
|
|||||||||||