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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.