Parent-Detail Binding

One of the things that hasn't yet been covered in this chapter is the parent-detail binding pattern. This is a common situation where the user navigates through rows in a parent table and each of those rows is the parent row for child rows in another table. The example most commonly used to illustrate this is when dealing with an Orders table and an OrderDetails table. While the user is browsing through the list of orders, a list of order items appears every time the user changes the current order.

Binding with a parent-child relationship is just as easy as binding to a regular data source. With a typed DataSet, you bind the parent control to the parent table, just as you normally would. Then, for the child view, you simply bind to the DataRelation (often named with an "FK_" prefix indicating that the data relation is a foreign key) that dictates the parent-child relationship. After you do this, the parent-child relationship will be reflected in the GUI.

As an exercise, take the information that you have learned throughout this chapter and try to build your own parent-detail data binding. You can use all of the data-binding techniques covered in this chapter to create the parent binding, and then when selecting a data source for the child records, simply select the data relation rather than the child table itself.

Microsoft Visual C# 2005 Unleashed
Microsoft Visual C# 2005 Unleashed
ISBN: 0672327767
EAN: 2147483647
Year: 2004
Pages: 298 © 2008-2017.
If you may any questions please contact us: