O'Reilly logo

Windows Forms Programming in C# by Chris Sells

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Data Binding

In Windows Forms development, there often comes a time when you need to populate a number of controls with data from a database or other data source. Recall our example from Chapter 12: Data Sets and Designer Support, which used a data set populated from a database. Whenever the data set was changed, such as when the user added a row or deleted a row, we had to repopulate the list boxes so that the display was kept in sync with the data:

void addRowMenuItem_Click(object sender, EventArgs e) {
  // Add a new typed row
					CustomerSet.CustomersRow row =
					this.customerSet1.Customers.NewCustomersRow();
  row.CustomerID = "SELLSB";
  ...
					this.customerSet1.Customers.AddCustomersRow(row);

  // Update list box
  PopulateListBox();
}

Writing code to do ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required