By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,890 Members | 1,273 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,890 IT Pros & Developers. It's quick & easy.

Totally confused Relation/Bindingcontext/EndCurrentEdit(), etc

P: n/a
Hi there,

Can anyone help me with a definitive solution to the problem I have. I know
this is much revisitied ground, and I have read a number of articles.. but I
still can;t get this binding to work.

Let me explain...

I have a form which displays records from a dataset in a textboxes.

So, I define my BMB...

bmbLinkMAN_farm_trans = Me.BindingContext(dsLinkMAN_farm_trans_1,

To complicate matters, I want, in one of the text boxes, to display a column
value from another table in my dataset, based on a compund-column
So, in my farm_trans table I have two columns 'year' and 'farm_id' - I want
to use these values to create a relationship with the respective columns in
the 'farm' table for which these two columns are a compound primary key.
This isn't strictly a parent/child relationship - it is more of a lookup
type of relationship I am trying to define... if it was parent/child, you
could say I had potentially a lot of orphaned records in the farm table...
So, I create a relationship....

Dim parentTable As DataTable =
Dim childTable As DataTable = dsLinkMAN_farm_trans_1.Tables("farm")
'setup the relations
Dim columns_a() As DataColumn
Dim columns_b() As DataColumn
columns_a = New DataColumn() {parentTable.Columns("year"),
columns_b = New DataColumn() {childTable.Columns("year"),
dsLinkMAN_farm_trans_1.Relations.Add("ParentToChil d", columns_a,
columns_b, False)

And then I add my databinding to the textbox;

txtNMANfarmname.DataBindings.Add("Text", parentTable,

Now, I have a couple of navigation-type of buttons on my form, which
essentially scroll through the dataset...

Private Sub NavigationButtons_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnPrevious.Click, btnNext.Click
Select Case sender.Name
Case "btnPrevious"
bmbLinkMAN_farm_trans.Position -= 1

Case "btnNext"
bmbLinkMAN_farm_trans.Position += 1
End Select
End Sub

And the DisplayPosition() Sub which confirms that I am indeed scrolling
through the dataset - as you can see I have tried numerous methods of
invoking EndCurrentEdit() with no luck..

Private Sub DisplayPosition()
txtNMANfarmname.DataBindings("Text").BindingManage rBase.EndCurrentEdit()
' Me.BindingContext(dsLinkMAN_farm_trans_1,
' bmbLinkMAN_farm_trans.EndCurrentEdit()
btnPrevious.Enabled = Not (bmbLinkMAN_farm_trans.Position = 0)
btnNext.Enabled = Not (bmbLinkMAN_farm_trans.Position =
bmbLinkMAN_farm_trans.Count - 1)
stsbar.Text = bmbLinkMAN_farm_trans.Position + 1 & " of " &
bmbLinkMAN_farm_trans.Count & " farms found."
End Sub

Now, when the form runs, the FIRST farm_name DOES appear in the text box,
but if I move through the BMB - it doesn't update...
however, if I navigate through a datagrid that I add to the form bound to
the same dataset, it does.....
I;m sure I must be doing something wrong.. but I can;t see what it is... can
anyone PLEEEEEASSSEE help?

Incidentally, if I bind one of the 'parent' table columns to the textbox it
works correctly.... could this be an issue more with the relationship?

Nov 20 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.