Assuming both forms are declared simulatneously and will exist together, you
can just use the same underlying dataset/datatable. You can use a
datarelation object
http://www.knowdotnet.com/articles/datarelation.html
to enforce your relationships, and when you provided you are using a
BindingContext, when you switch from record to another, the corresponding
records will be pulled in.
On thing you may want to do is create your dataset/datatables as a module or
static properties. Then you can reference them from any form.
Now, assuming you have Bmb declared but not initialized as a
BindingManagerBase..here's a sample of how to implement it with various
controls:
Sub InitializeBinding()
Try
bmb = Me.BindingContext(Ds1, "Employees")
bmb.Position = 0
tbFirstName.DataBindings.Add("Text", Ds1, "Employees.FirstName")
tbTotalLeave.DataBindings.Add("Text", Ds1,
"Employees.Leave_Accrued")
tbLastName.DataBindings.Add("Text", Ds1, "Employees.LastName")
tbTitle.DataBindings.Add("Text", Ds1, "Employees.Title")
Ds1.Tables("Leave").Columns(6).ColumnMapping =
MappingType.Hidden
dgLeave.DataSource = Ds1
dgLeave.DataMember = "Employees.EmpLeave"
Call AddCustomColumnStyle(dgLeave, Ds1)
dgNotes.DataSource = Ds1
dgNotes.DataMember = "Employees.EmpNotes"
dgReview.DataSource = Ds1
dgReview.DataMember = "Employees.EmpReview"
dgPayroll.DataSource = Ds1
dgPayroll.DataMember = "Employees.Payroll"
dgUOneVAVPN.DataSource = Ds1
dgUOneVAVPN.DataMember = "Employees.oneVARel"
dgUVista.DataSource = Ds1 '.Tables("Vista")
dgUVista.DataMember = "Employees.VistaRel"
Catch ex As System.Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
I have multiple relationships set up which are declared as follows (my
naming conventions are a bit sloppy, this was an early project and I was
just playing around, but the logic is sound..
'Assuming that all of the respective Tables of Ds1 have already been
populated
Private Sub BuildAndBindRelations()
Dim parentCol As DataColumn
Dim childCol As DataColumn
Dim childColNotes As DataColumn
Dim childColReviews As DataColumn
Dim parentColType As DataColumn
Dim childColType As DataColumn
Dim childColPayroll As DataColumn
Dim vistaCol As DataColumn
Dim oneVaCol As DataColumn
Dim relCustOrder As DataRelation
Dim recNotes As DataRelation
Dim recReviews As DataRelation
Dim recType As DataRelation
Dim relPayroll As DataRelation
Dim relVista As DataRelation
Dim oneVARel As DataRelation
parentCol = Ds1.Tables("Employees").Columns(9)
childCol = Ds1.Tables("Leave").Columns(0)
childColNotes = Ds1.Tables("Notes").Columns(0)
childColReviews = Ds1.Tables("Reviews").Columns(0)
parentColType = Ds1.Tables("Employees").Columns(32)
childColType = Ds1.Tables("Types").Columns(0)
childColPayroll = Ds1.Tables("Payroll").Columns(0)
vistaCol = Ds1.Tables("Vista").Columns(0)
oneVaCol = Ds1.Tables("OneVa").Columns(0)
relCustOrder = New DataRelation("EmpLeave", parentCol, childCol)
recNotes = New DataRelation("EmpNotes", parentCol, childColNotes)
recReviews = New DataRelation("EmpReview", parentCol,
childColReviews)
relPayroll = New DataRelation("Payroll", parentCol, childColPayroll)
relVista = New DataRelation("VistaRel", parentCol, vistaCol)
oneVARel = New DataRelation("oneVaRel", parentCol, oneVaCol)
' Create DataRelation.
Ds1.Relations.Add(relCustOrder)
Ds1.Relations.Add(recNotes)
Ds1.Relations.Add(recReviews)
Ds1.Relations.Add(relPayroll)
Ds1.Relations.Add(relVista)
Ds1.Relations.Add(oneVARel)
InitializeBinding()
End Sub
Now, I have a call to update datasets which I call when the user hits an
update button or closes the form if DataSet1.HasChanges. YOu can modify
this as you see fit, I chose to call it as seldom as possible b/c the data
doesn't change very much:
Public Sub UpdateDataSets()
Try
da.Update(Ds1, "Employees")
daLeave.Update(Ds1, "Leave")
daNotes.Update(Ds1, "Notes")
daReviews.Update(Ds1, "Reviews")
daTitles.Update(Ds1, "Titles")
daTypes.Update(Ds1, "Types")
daPayroll.Update(Ds1, "Payroll")
daVista.Update(Ds1, "Vista")
daOneVa.Update(Ds1, "OneVa")
Catch ex As System.Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
When this is all done, every time you move to a new record using
bmb.Position +=1 for instance, the data in the related tables populates
itself in the respective grids.
I can send you the full code if you want.... HTH,
Bill
Bamse said:
Hi all!
i have this problem:
i need to synchronize 2 datagrids in 2 different forms upon the Master
Details model.
i want to do this using BindingContext, BindingManagerBase.
can you give me any directions? (i've read the msdn topics concerning
this stuff)
Thank you,
Bamse
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption
=---