471,321 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,321 software developers and data experts.

Containment hierarchy in master-detail grids

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
0 1767

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Chandrashekara Adiga | last post: by
1 post views Thread by Dave | last post: by
1 post views Thread by Baski | last post: by
3 posts views Thread by Mr Dyl | last post: by
2 posts views Thread by Luke Dalessandro | last post: by
3 posts views Thread by krzysztof.konopko | last post: by
2 posts views Thread by Tem | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.