By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,084 Members | 1,266 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,084 IT Pros & Developers. It's quick & easy.

Containment hierarchy in master-detail grids

P: n/a
This post is for the Google crawler-- no response in required.

Can a containment hierarchy made up of two collections derived from
BindingList<T> be data-bound to master-detail dataGridView controls?

Assume a collection, CustomerList, derived from BindingList<T>, with a
property Orders, of type OrderList, also derived from BindingList<T>. Here
is how to create a master-detail pair of grids:

In design mode, create a form with two dataGridView controls, dgvCustomers
and dgvOrders. Add two BindingSource components, bsCustomers, and bsOrders.
Set the DataSource for dgvCustomers to bsCustomers, and set the DataSource
for bsCustomers to the CustomerList object. Set the DataSource for DGVOrders
to bsOrders. Now, here's the trick--set the DataSource for bsOrders to
bsCustomers. Drop down the list for bsOrders' DataMember property, and you
will see "Orders". Select that, and dgvOrders will show the OrderList
properties as columns.

At this point, both grids can be configured and formatted as desired. But
all we've really done is bound the grids to our objects' schema--we still
need to wire up the run time customer list. One line of code will do it.
Assume the CustomerList is contained in a member variable variable

bsCustomers.DataSource = m_Customers;

Now the two grids will behave as a master-detail pair. As different
customers are selected in dgvCustomers, dgvOrders will update to show those
customers' orders.

Jan 4 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.