G
Guest
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.Rowfilter 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.SqlDataAdapter("Select * From PrimaryTbl",
conn)
Dim daSecondary As New SqlClient.SqlDataAdapter("Select * From
SecondaryTbl", conn)
daPrimary.Fill(ds, "Prinmary")
daSecondary.Fill(ds, "Secondary")
ds.Relations.Add("relPrimarySecondary", ds.Tables("Primary").Columns("ID"),
ds.Tables("Secondary").Columns("SubID"))
DataGridView1.DataSource = ds
DataGridView1.DataMember = "Primary.relPrimarySecondary"
curMgr = CType(Me.BindingContext(ds.Tables("Primary")), CurrencyManager)
curMgr.Position = 0
Me.txt0.DataBindings.Add("Text", ds.Tables("Primary"), "ID")
Me.txt1.DataBindings.Add("Text", ds.Tables("Primary"), "fName")
Me.txt2.DataBindings.Add("Text", ds.Tables("Primary"), "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
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.Rowfilter 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.SqlDataAdapter("Select * From PrimaryTbl",
conn)
Dim daSecondary As New SqlClient.SqlDataAdapter("Select * From
SecondaryTbl", conn)
daPrimary.Fill(ds, "Prinmary")
daSecondary.Fill(ds, "Secondary")
ds.Relations.Add("relPrimarySecondary", ds.Tables("Primary").Columns("ID"),
ds.Tables("Secondary").Columns("SubID"))
DataGridView1.DataSource = ds
DataGridView1.DataMember = "Primary.relPrimarySecondary"
curMgr = CType(Me.BindingContext(ds.Tables("Primary")), CurrencyManager)
curMgr.Position = 0
Me.txt0.DataBindings.Add("Text", ds.Tables("Primary"), "ID")
Me.txt1.DataBindings.Add("Text", ds.Tables("Primary"), "fName")
Me.txt2.DataBindings.Add("Text", ds.Tables("Primary"), "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