Bind a Field to a List Control, and Restrict It to the Values from Another Table

Problem

You want to fill a list control with allowed values from one table and use it to edit a field in another table.

Solution

Fill the list control with allowed values by setting the DataSource, DisplayMember, and ValueMember properties. Then bind the list control’s SelectedValue to the field you want to edit using the DataBindings collection.

Discussion

List controls can play two roles in Windows data binding:

  • Record navigation. In this case, you set the DataSource, DisplayMember, and ValueMember properties. For example, if you bind the list control in this way to the ProductName column in a Products table, the list will be filled with all the product names in the table. ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook 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.