I need to allow users to search on any criteria in a multiple table (with multiple relations) dataset. Once the criteria is entered and the user presses the search button, I'd like to allow the user to scroll through a list box containing a key field of each of the found records. As each of the key fields is selected in the list box, all records tied to that key will show up on the form. There are many tables, and I haven’t gotten binding filtering or dataset selects or DataViewManagers to work. So far, creating a view of all the tables and running the following code comes closest to working. This is a very simplistic version (using only one search criteria) of what I’ve currently got:
Private Sub SearchButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchButton.Click
Me.tblChildForSearchTableAdapter.FillByUser(Me.DsSearch. tblChildForSearch, SearchTextBox.Text)
'Create a table of distinct DocIDs
Dim Parentdt As DataTable
'Parentdt = DsSearch.VwAllDocSearch.DefaultView.ToTable(True, "DocID")
Parentdt = DsSearch. tblChildForSearch.DefaultView.ToTable(True, New String() {"DocID", "IndexNo", "FileNo"})
'Get the number of rows in the new table
Dim parentdtCount As Integer
parentdtCount = Parentdt.Rows.Count
'Copy the rows in parentdt to tblParentForSearch
For i = 0 To parentdtCount - 1
DsSearch.tblParentForSearch.ImportRow(Parentdt.Rows(i))
Next
'Create a parent,child relation between tblParentForSearch and tblChildForSearch
Dim colChildID As DataColumn = DsSearch. tblChildForSearch.Columns("DocID")
Dim colParentID As DataColumn = DsSearch.tblParentForSearch.Columns("DocID")
Dim dr As DataRelation
dr = New DataRelation("Parent2Child", colParentID, colChildID)
'Set up binding sources
Dim ParentBindingSource = New BindingSource
With ParentBindingSource
.DataMember = "tblParentForSearch"
.DataSource = DsSearch
End With
Dim ChildBindingSource = New BindingSource
With ChildBindingSource
.DataMember = "Parent2Child"
.DataSource = ParentBindingSource
End With
End Sub
I then bind a listbix to the ParentBindingSource and a datagridview to the ChildBindingSource. Although both objects fill with the correct data, there’s no binding or connection between the two. I'm not sure where I'm going wrong.
I have about 10 child tables and 1 parent table. This is the only thing I’ve come up with that’s come close to working. Any insight on my code or other ways to accomplish this would be very appreciated!