Data Binding

In WinForms 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:

Sub addRowMenuItem_Click(sender As Object, e As EventArgs)
  ' Add a new typed row
  Dim row As CustomerSet.CustomersRow = _
      Me.customerSet1.Customers.NewCustomersRow()
  row.CustomerID = "SELLSB"
  ...
  Me.customerSet1.Customers.AddCustomersRow(row)

  ' Update list box
  PopulateListBox()
End Sub

Writing code to ...

Get Windows Forms Programming in Visual Basic .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.