I just expalined how to do this earlier today with two DataGridViews. Check out this thread for an example. Now, because you are displaying your parent records in a ListBox instead of a DataGridView this part:would become this:vb.net Code:
Me.BindingSource1.DataSource = data.Tables("Parent") Me.DataGridView1.DataSource = Me.BindingSource1 Me.DataGridView2.DataMember = "ParentChild" Me.DataGridView2.DataSource = Me.BindingSource1Now, to set up the realtion and the binding using your table and column names:vb.net Code:
Me.BindingSource1.DataSource = data.Tables("Parent") Me.ListBox1.ValueMember = "ID" Me.ListBox1.DisplayMember = "Name" Me.ListBox1.DataSource = Me.BindingSource1 Me.DataGridView2.DataMember = "ParentChild" Me.DataGridView2.DataSource = Me.BindingSource1If you have created a typed DataSet then all of this can be set up in the designer with no code at all. If that's the case then let me know and I'll give you the instructions.vb.net Code:
Dim relation As New DataRelation("CategoriesItems", _ parentTable.Columns("CatID"), _ childTable.Columns("CatID")) data.Relations.Add(relation) Me.BindingSource1.DataSource = data.Tables("Categories") Me.ListBox1.ValueMember = "CatID" Me.ListBox1.DisplayMember = "CatDesc" Me.ListBox1.DataSource = Me.BindingSource1 Me.DataGridView2.DataMember = "CategoriesItems" Me.DataGridView2.DataSource = Me.BindingSource1




Reply With Quote