Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Stuck on data relations, but I think I'm close
 

Stuck on data relations, but I think I'm close

Well, I'm trying everything I can think of, but I just can't get this working.  I have two tables... Category(parent), Items(child).  All I want to do is show the Categories in listbox1, and the items with the corresponding CategoryID (the selected CategoryID) in listbox2.  I've come pretty close (thanks to jmcilhinney, and MSDN) but I just can't seem to get it.  Here is what I have.  It shows the parent child relationships in listbox1 only.  I just need to move the items to listbox2, and have them respond to the selected category in listbox1.

OleDbDataAdapter1.Fill(Dsboth1)
OleDbDataAdapter2.Fill(Dsboth1)

For Each dr1 In Dsboth1.Tables("Category").Rows
            ListBox1.Items.Add(("Category: " + dr1("CategoryName").ToString()))
            For Each dr2 In dr1.GetChildRows(Dsboth1.Relations("MYDR"))
                ListBox1.Items.Add(("Items: " + dr2("ItemName").ToString()))
            Next
Next
MigrationUser 1  Tuesday, May 10, 2005 11:42 PM
How about letting DataBinding do the work for you?

OleDbDataAdapter1.Fill(Dsboth1) 
OleDbDataAdapter2.Fill(Dsboth1) 

'Add your relationship named "MYDR" to the dataset here!

ListBox1.DataSource = Dsboth1.Tables("Category")
ListBox1.DisplayMember = "CategoryName"

ListBox2.DataSource = Dsboth1.Tables("Category")
ListBox2.DisplayMember = "MYDR.ItemName"
MigrationUser 1  Wednesday, May 11, 2005 11:36 AM

You can use google to search for other answers

Custom Search

More Threads

• DataGridView & CellValidating
• How do I refresh a DataGridView after adding a row programatically?
• Binding 2 Forms
• Object Data Source
• VB.net - datagridview cannot show the query that has LIKE
• change connection string (for TableAdapter or DataAdapter) at runtime
• Enforce Constraints question
• DataGridviewComboBox Default Value
• Column Format in unbound DataGridView
• BindingList and CancelEdit using databound controls