How to: Create Lookup Tables
You can create lookup tables by dragging the main node of a parent table (from the) onto a control on your form that is already bound to the column in the related child table.
The term lookup table describes controls that are bound to two related data tables. These lookup controls display data from the first table based on a value selected in the second table.
For example, consider a table of Orders in a sales database. Each record in the Orders table includes a CustomerID indicating which customer placed the order. The CustomerID is a foreign key pointing to a customer record in the Customers table. In this scenario you would expand the Orders table in the Data Sources window and set the main node to Details, set the CustomerID column to use a(or any other control that supports lookup binding), and drag the Orders node onto your form. Then you would drag the Customers node onto the control that is bound to the related column — in this case, the ComboBox bound to the CustomerID column.
To databind a lookup control
Open the Data Sources window.
Lookup tables require that two related tables or objects are available in the Data Sources window. For more information, see.
Expand the nodes in the Data Sources window until you can see the parent table and all of its columns, and the related child table and all of its columns.
The child table node is the node that appears as an expandable child node in the parent table.
Change the drop type of the child table to Details by selecting Details from the control list on the child table's node. For more information, see.
Locate the node that relates the two tables (the CustomerID node in the example above) and change its drop type to a ComboBox by selecting ComboBox from the control list.
Drag the main child table node from the Data Sources window onto your form.
Now drag the main parent table node from the Data Sources window directly onto the lookup control (the ComboBox).
The lookup bindings are now established. Refer to the table below for the specific properties that were set on the control.
Property Explanation of setting
Visual Studio sets this property to the BindingSource created for the table you drag onto the control (as opposed to the BindingSource created when the control was created).
If you need to make an adjustment, then set this to the BindingSource of the table with the column you want to display.
Visual Studio sets this property to the first column after the primary key that has a string data type for the table you drag onto the control.
If you need to make an adjustment, then set this to the column name you want to display.
Visual Studio sets this property to the first column participating in the primary key, or the first column in the table if no key is defined.
If you need to make an adjustment, then set this to the primary key in the table with the column you want to display.
Visual Studio sets this property to the original column dropped from the Data Sources window.
If you need to make an adjustment, then set this to the foreign-key column in the related table.