Is There a Simpler Way To Display Parent/Child Data in Two ComboBox Controls

B

Bob Johnson

..NET 3.5, Windows Forms app: My objective is to display parent/child data in
two ComboBox controls, such that when a parent item is selected in one combo
box, associated child items appear in the other combo box.

I already know one way to make this work using two DataTables and a
DataView, and handling the SelectionChangeCommitted event of the parent
ComboBox so that it sets the .RowFilter of the DataView to which the child
ComboBox is bound.

But what I am wondering is if there is a simpler way to get the job done
using a DataSet with the two DataTables and a DataRelation to set up the
parent/child relationship. I have set up a DataSet as described, but the
child ComboBox (which is bound to the child DataTable in the
DataSet)displays *all* rows from the child DataTable, completely ignoring
the DataRelation, when I am wanting for it to display only the child rows
related to the currently selected parent DataRow.

Am I just missing something, or do I really need to go with the DataView
approach?

Thanks!
 
N

Nicholas Paldino [.NET/C# MVP]

Bob,

You don't need to do any of the filtering at all. If you have the
DataRelation set up between the two tables, then you can bind the child
combo box to the data relation, and on change of the parent, the child list
will show only the items related to the parent.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top