PDA

Click to See Complete Forum and Search --> : DataRelation & Binding Not Working!!


adsc
Feb 22nd, 2003, 11:01 AM
I have created a one to one relation between parent “member” table and a child “Measurements” table, the relation works fine.
The problem is, the child table displayed in a DataGrid in the upper area of the form, & the bottom area I have some textbox which the data in the DataGrid binded to it, meaning when the user clicks on any row in the DataGrid, details should appear in this textboxs, but this is not happening !!!

I wonder if I have a coding error, next is the code used:

myDA.Fill(myDS, "Member")
myMeasureDA.Fill(myDS, "Measure")

‘ Add DataRelation the DataSet
myDS.Relations.Add("MemMsr", myDS.Tables("Member").Columns("MemberID"), myDS.Tables("Measure").Columns("MemberID"))

' cbSelect Member DataSource
Me.cbSelect.DataSource = myDS.Tables("Member")
Me.cbSelect.DisplayMember = "MemberID"

‘ Bind data in the first window form
Me.txtMemberName_e.DataBindings.Add("Text", myDS.Tables("Member"), "Name_e")

Me.dgMeasurements.DataSource = myDS.Tables("Measure")

‘ the next line is spoiling my next databinding
Me.dgMeasurements.SetDataBinding(myDS, "Member.MemMsr")

‘ bind the 2nd window form (*** this binding get spoiled ***)
Me.txtWeight.DataBindings.Add("Text", myDS.Tables("Measure"), "Weight")
Me.txtHeight.DataBindings.Add("Text", myDS.Tables("Measure"), "Height")

Any idea where is the problem?

Thanks for the help

Lunatic3
Feb 22nd, 2003, 02:56 PM
I couldnt exactly understand what you need, please describe more clearly.
Anyway considering that you have:
1- A master table called :Members
2- A details table called : Measurments
3- A datarelation object called: MemMsr
4- A dataset called myDS
5- A datagrid called:dgMeasurements
6- Two textboxes called: txtHeight, txtWeight
Then in order to have the data in the 'Members' table in datagrid and the details of each row in two textboxes then you may:
1-Bind your datagrid to the master table
2-Set AllowNavigation property of datagrid to False
3- Bind Textboxes as follows:
Me.txtWeight.DataBindings.Add("Text", Me.myDS, "Members.MemMsr.Weight")
or
Me.txtWeight.DataBindings.Add("Text", Me.myDS, "Members.MemMsr.Height")

adsc
Feb 23rd, 2003, 03:19 AM
Lunatic3 thank you for your reply.

Your understanding is correct till # 6 but....after that, Members data are displayed in a tab form (click to see the image)
http://www.adsc.net/cms/club0.jpg
And Measurements data are displayed in the Grid, if I clicked any Grid row the Measurements FULL info will be displayed in the save form under the grid in a texbox (http://www.adsc.net/cms/club1.jpg)

When I bind the Measurements data to the textbox as follow:
Me.txtWeight.DataBindings.Add("Text", myDS.Tables("Measure.MemMsr"), "Weight")
I get a run-time error says "value can't be null", while I don't see any thing null

Any idea please.

Lunatic3
Feb 23rd, 2003, 10:25 AM
From what I gathered you want to select an ID in Personl Tab, then going to the Measurments Tab you have several measurments of each ID and the selecting each of them will show you full details in textboxes in panel below. If that's what you want then do this:

Me.dgMeasurements.SetDataBinding(myDS, "Member.MemMsr")
Me.txtWeight.DataBindings.Add("Text", myDS,"Members.MemMsr.Wight")


you have to keep the syntax the same to keep synchronization. By the way MemMsr is a member of Members table (master table) not the child table.

adsc
Feb 24th, 2003, 10:37 AM
Excellent Lunatic3,

The mistake I was making is, I was binding to Measure DataSet not to the Relation !!

Thank you very much Lunatic3, you made my day :D

Lunatic3
Feb 24th, 2003, 11:04 AM
you're most welcome! :)