Hello,
Following an example at
http://www.vb-tips.com/dbpages.aspx?IA=DG (by Cor Lightert and Ken Tucker)
on binding a dataRelation to a Datagridview for sqlClient, I was able to
view rows in datagridview2 that corresponded to a selected row in
datagridview1. Great article/example.
Now I am navigating through the primary table using currencyManager and
displaying the data in textboxes rather than a datagridview. But I am still
using a datagridview for the secondary table. I bind the currencymanager to
the primary table, and I have a datarelation between the primary table and
the secondary table. But when I move to another row in the primary table
using the currencymanager , the datagridview is not displaying the
corresponding rows in the secondary table.
Is there a way I can navigate the primary table using currency manager and
display the corresponding rows of the secondary table in the datagridview
using the datarelation? I was previously using a dataview and the
dataview.Rowfil ter for synchronizing the datagridview rows with the current
row in the primary table. This technique worked, but I believe the
datarelation method is better. Here is the code I am using for the
datarelation and currencty manager technique:
Priavate Sub Form1_Load(...)
....
Dim daPrimary As New SqlClient.SqlDa taAdapter("Sele ct * From PrimaryTbl",
conn)
Dim daSecondary As New SqlClient.SqlDa taAdapter("Sele ct * From
SecondaryTbl", conn)
daPrimary.Fill( ds, "Prinmary")
daSecondary.Fil l(ds, "Secondary" )
ds.Relations.Ad d("relPrimarySe condary", ds.Tables("Prim ary").Columns(" ID"),
ds.Tables("Seco ndary").Columns ("SubID"))
DataGridView1.D ataSource = ds
DataGridView1.D ataMember = "Primary.relPri marySecondary"
curMgr = CType(Me.Bindin gContext(ds.Tab les("Primary")) , CurrencyManager )
curMgr.Position = 0
Me.txt0.DataBin dings.Add("Text ", ds.Tables("Prim ary"), "ID")
Me.txt1.DataBin dings.Add("Text ", ds.Tables("Prim ary"), "fName")
Me.txt2.DataBin dings.Add("Text ", ds.Tables("Prim ary"), "lName")
End Sub
Private Sub btn1_Click(...)
curMgr.Position += 1
End Sub
The currencymanager will iterate through the primary table. Is it possible
to synchronize the datagridview with the primary table using a datarelation?
How to do this?
Thanks,
Rich