BindingManagerBase Not Working

G

Guest

I have a Windows form with textboxes, labels, comboboxes, and a listbox. I bind the database fields to those objects and would like the user to be able to click through them (forward, back, first, last). The navigation buttons are not working. I commented out the combobox code b/c I read somewhere that could be causing the problem. That didn't work. What am I doing wrong. Thanks.

Private Sub btnGetRecords_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetRecords.Click

If cboDept.SelectedIndex = 0 Then
MessageBox.Show("You must select an area.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error)
cboDept.Focus()
Else
Try
sb.Append("SELECT e.eqnum, nvl(purpose, ' ') AS purpose,")
sb.Append(" NVL(theory_of_operation,' ') AS theory_of_operation,")
sb.Append(" NVL(similar_devices, ' ') AS similar_devices,")
sb.Append(" NVL(level_nbr, 1) As level_nbr, l.description AS unit_op,")
sb.Append(" nvl(me.description, ' ') AS description, e.tagged")
sb.Append(" FROM dbo.th_equipment e, dbo.equipment@MAXLDA_P me, ")
sb.Append("dbo.locations@MAXLDA_P l ")
sb.Append("WHERE me.location LIKE '%")
sb.Append(CType(cboDept.SelectedItem, ItemData).Key)
sb.Append("%' AND ")
sb.Append("SubStr(me.location,1,5) = l.location AND ")
sb.Append(" me.eqnum=e.eqnum")
sb.Append(" ORDER BY e.eqnum")

da.SelectCommand.CommandText = sb.ToString()
da.Fill(ds, "equipment")

sb.Remove(0, sb.Length)
sb.Append("SELECT eqnum, issue_id FROM dbo.th_equipment_issue")

Dim cmdEqIssues As New OleDb.OleDbCommand(sb.ToString, conn)
Dim daEqIssues As New OleDb.OleDbDataAdapter(cmdEqIssues)
daEqIssues.Fill(ds, "equipment_issues")

sb.Remove(0, sb.Length)

sb.Append("SELECT issue_id, description FROM dbo.th_issue ")
sb.Append("ORDER BY description")

Dim cmdIssues As New OleDb.OleDbCommand(sb.ToString(), conn)
Dim daIssues As New OleDb.OleDbDataAdapter(cmdIssues)
daIssues.Fill(ds, "issues")

Dim equip_issue_rel As New DataRelation("eq_issue_rel", ds.Tables(0).Columns("eqnum"), ds.Tables(1).Columns("eqnum"))
ds.Relations.Add(equip_issue_rel)

Dim issue_rel As New DataRelation("is_rel", ds.Tables(2).Columns("issue_id"), ds.Tables(1).Columns("issue_id"))
ds.Relations.Add(issue_rel)

lbSelectedIssues.DataSource = ds.Tables("issues")
lbSelectedIssues.DisplayMember = ds.Tables("issues").Columns(1).ColumnName
lbSelectedIssues.ValueMember = ds.Tables("issues").Columns(0).ColumnName
lbSelectedIssues.DataBindings.Add("SelectedValue", ds.Tables("equipment_issues"), "issue_id")

txtPurpose.DataBindings.Add("Text", ds.Tables("equipment"), "purpose")
lblEQNUM.DataBindings.Add("Text", ds.Tables("equipment"), "eqnum")
lblUnitOp.DataBindings.Add("Text", ds.Tables("equipment"), "unit_op")
lblDescription.DataBindings.Add("Text", ds.Tables("equipment"), "description")
txtTheoryOfOperation.DataBindings.Add("Text", ds.Tables("equipment"), "theory_of_operation")
txtSimilarDevices.DataBindings.Add("Text", ds.Tables("equipment"), "similar_devices")

' cboLevel.DataSource = ds.Tables("equipment")
' cboLevel.DisplayMember = "level_nbr"
' cboLevel.ValueMember = "level_nbr"
'cboLevel.DataBindings.Add("SelectedValue", ds.Tables("equipment"), "level_nbr")


' cboTagged.DataSource = ds.Tables("equipment")
' cboTagged.DisplayMember = "tagged"
' cboTagged.ValueMember = "tagged"
'cboTagged.DataBindings.Add("SelectedValue", ds.Tables("equipment"), "tagged")

eqBindingManagerBase = Me.BindingContext(ds, "equipment")


Catch ex As Exception
MessageBox.Show("Encountered error when getting records.", "System Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try

End If

End Sub

Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click
eqBindingManagerBase.Position = eqBindingManagerBase.Count - 1
End Sub

Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click
eqBindingManagerBase.Position = 0
End Sub

Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click
eqBindingManagerBase.Position -= 1
End Sub

Private Sub btnForward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnForward.Click
eqBindingManagerBase.Position += 1
End Sub
 
W

William Ryan eMVP

Can you change the position at all, hard code it to something? There's an
issue with Checkboxes but if you set everythign up right, that shouldn't be
a problem w/ comboboxes. ALso, I'm not sure if it's a problem or not, but I
think you should add the bindingmanger before you add each of the
bindings...I use almost the indentical code and all looks well except I add
the BMB right before adding each of the databindings.

Not sure exactly what else it could be if you've verified that you have all
more than 1 rows and all that , it's usually a checkbox that's bound
somewhere. Here's a sample ofa snippet I use..identical other than where I
set teh BMB:

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")
tbSupervisors.DataBindings.Add("Text", Ds1, "Employees.Supervisor")
tbHireDate.DataBindings.Add("Text", Ds1, "Employees.DateHired")
tbSSN.DataBindings.Add("Text", Ds1, "Employees.SSN")
tbReviewDate.DataBindings.Add("Text", Ds1, "Employees.Review_Date")
tbDOB.DataBindings.Add("Text", Ds1, "Employees.BirthDate")
tbEmail.DataBindings.Add("Text", Ds1, "Employees.Email_Address")
tbExtension.DataBindings.Add("Text", Ds1, "Employees.Ext")
tbAddress.DataBindings.Add("Text", Ds1, "Employees.Address")
tbCity.DataBindings.Add("Text", Ds1, "Employees.City")

'ComboBoxes
cbEmpType.DataBindings.Add("SelectedItem", Ds1, "Employees.Emp_Type")
cbEmpType.DataBindings.Add("SelectedValue", Ds1,
"Employees.Emp_Type")

End Sub

--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
http://www.devbuzz.com/content/zinc_personal_media_center_pg1.asp
Greg said:
I have a Windows form with textboxes, labels, comboboxes, and a listbox. I
bind the database fields to those objects and would like the user to be able
to click through them (forward, back, first, last). The navigation buttons
are not working. I commented out the combobox code b/c I read somewhere that
could be causing the problem. That didn't work. What am I doing wrong.
Thanks.
Private Sub btnGetRecords_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnGetRecords.Click
If cboDept.SelectedIndex = 0 Then
MessageBox.Show("You must select an area.", "Error!",
MessageBoxButtons.OK, MessageBoxIcon.Error)
cboDept.Focus()
Else
Try
sb.Append("SELECT e.eqnum, nvl(purpose, ' ') AS purpose,")
sb.Append(" NVL(theory_of_operation,' ') AS theory_of_operation,")
sb.Append(" NVL(similar_devices, ' ') AS similar_devices,")
sb.Append(" NVL(level_nbr, 1) As level_nbr, l.description AS unit_op,")
sb.Append(" nvl(me.description, ' ') AS description, e.tagged")
sb.Append(" FROM dbo.th_equipment e, dbo.equipment@MAXLDA_P me, ")
sb.Append("dbo.locations@MAXLDA_P l ")
sb.Append("WHERE me.location LIKE '%")
sb.Append(CType(cboDept.SelectedItem, ItemData).Key)
sb.Append("%' AND ")
sb.Append("SubStr(me.location,1,5) = l.location AND ")
sb.Append(" me.eqnum=e.eqnum")
sb.Append(" ORDER BY e.eqnum")

da.SelectCommand.CommandText = sb.ToString()
da.Fill(ds, "equipment")

sb.Remove(0, sb.Length)
sb.Append("SELECT eqnum, issue_id FROM dbo.th_equipment_issue")

Dim cmdEqIssues As New OleDb.OleDbCommand(sb.ToString, conn)
Dim daEqIssues As New OleDb.OleDbDataAdapter(cmdEqIssues)
daEqIssues.Fill(ds, "equipment_issues")

sb.Remove(0, sb.Length)

sb.Append("SELECT issue_id, description FROM dbo.th_issue ")
sb.Append("ORDER BY description")

Dim cmdIssues As New OleDb.OleDbCommand(sb.ToString(), conn)
Dim daIssues As New OleDb.OleDbDataAdapter(cmdIssues)
daIssues.Fill(ds, "issues")

Dim equip_issue_rel As New DataRelation("eq_issue_rel",
ds.Tables(0).Columns("eqnum"), ds.Tables(1).Columns("eqnum"))
ds.Relations.Add(equip_issue_rel)

Dim issue_rel As New DataRelation("is_rel",
ds.Tables(2).Columns("issue_id"), ds.Tables(1).Columns("issue_id"))
ds.Relations.Add(issue_rel)

lbSelectedIssues.DataSource = ds.Tables("issues")
lbSelectedIssues.DisplayMember = ds.Tables("issues").Columns(1).ColumnName
lbSelectedIssues.ValueMember = ds.Tables("issues").Columns(0).ColumnName
lbSelectedIssues.DataBindings.Add("SelectedValue",
ds.Tables("equipment_issues"), "issue_id")
txtPurpose.DataBindings.Add("Text",
ds.Tables("equipment"), "purpose")
lblEQNUM.DataBindings.Add("Text", ds.Tables("equipment"), "eqnum")
lblUnitOp.DataBindings.Add("Text", ds.Tables("equipment"), "unit_op")
lblDescription.DataBindings.Add("Text",
ds.Tables("equipment"), "description")
txtTheoryOfOperation.DataBindings.Add("Text",
ds.Tables("equipment"), "theory_of_operation")
txtSimilarDevices.DataBindings.Add("Text",
ds.Tables("equipment"), "similar_devices")
' cboLevel.DataSource = ds.Tables("equipment")
' cboLevel.DisplayMember = "level_nbr"
' cboLevel.ValueMember = "level_nbr"
'cboLevel.DataBindings.Add("SelectedValue",
ds.Tables("equipment"), "level_nbr")
' cboTagged.DataSource = ds.Tables("equipment")
' cboTagged.DisplayMember = "tagged"
' cboTagged.ValueMember = "tagged"
'cboTagged.DataBindings.Add("SelectedValue",
ds.Tables("equipment"), "tagged")
eqBindingManagerBase = Me.BindingContext(ds, "equipment")


Catch ex As Exception
MessageBox.Show("Encountered error when getting records.",
"System Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try

End If

End Sub

Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnLast.Click
eqBindingManagerBase.Position = eqBindingManagerBase.Count - 1
End Sub

Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnFirst.Click
eqBindingManagerBase.Position = 0
End Sub

Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnBack.Click
eqBindingManagerBase.Position -= 1
End Sub

Private Sub btnForward_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnForward.Click
 
W

William Ryan eMVP

Greg:

The times I've had problems it's been either the checkbox issue or something
wrong with one of my datarelations. since your bindings concern equipment
primarily, I did notice one thing that may be causing you an issue. Just to
test it, comment out the datarelations and lblSelectedIssues. I know these
are necessary to make the application work correctly, but I think it may be
causing you the problem. I'm not sure, but when this happens, I just try to
reduce it to something small, get one chunk to work and add stuff from there
until it doesn t.

If it's the listbox like I mention, you can just use the SelectedIndex of it
in the meantime to set the bmb.Position - not that that's the final
solution, but I think the binding of it coupled with the structure of the
relation may be the culprit. Also, as an aside of something that's going to
most likely give you grief in the future, that concatenated sql is probably
going to cause some headaches. If you need to submit updates, then you'll
probably want to at a minimum paramaterize it (even if you don't want to
submit updates, the code will be a lot easier to read) it adding the
parameters to the command's Parameters collection.

For right now though, one thing at a time. Comment out the binding to the
listbox at the onset and the relations, just temporarily and see if that
doesn't get you past the first part. If it does we can work backward from
there. The fact that the position is moving (usually if it's the checkbox
issue it won't move) makes me think it's working but related to the listbox
and its relationships.

I'll be around for a while so let me know what you come up with.

HTH,

Bill

--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
http://www.devbuzz.com/content/zinc_personal_media_center_pg1.asp
Greg said:
Ok, I put the bindingmanagerbase before I added the bindings. No luck. I
know the position is updating b/c when I go into Debug Mode, I can view the
eqBindingManagerBase.Position in the Immediate window. It updates, but the
fields don't change. Any ideas?
 
G

Guest

Hi Bill

Commented out the datarelations and the listbox - same result. The Position updates, but the fields do not refresh with the new data

Gre

----- William Ryan eMVP wrote: ----

Greg

The times I've had problems it's been either the checkbox issue or somethin
wrong with one of my datarelations. since your bindings concern equipmen
primarily, I did notice one thing that may be causing you an issue. Just t
test it, comment out the datarelations and lblSelectedIssues. I know thes
are necessary to make the application work correctly, but I think it may b
causing you the problem. I'm not sure, but when this happens, I just try t
reduce it to something small, get one chunk to work and add stuff from ther
until it doesn t

If it's the listbox like I mention, you can just use the SelectedIndex of i
in the meantime to set the bmb.Position - not that that's the fina
solution, but I think the binding of it coupled with the structure of th
relation may be the culprit. Also, as an aside of something that's going t
most likely give you grief in the future, that concatenated sql is probabl
going to cause some headaches. If you need to submit updates, then you'l
probably want to at a minimum paramaterize it (even if you don't want t
submit updates, the code will be a lot easier to read) it adding th
parameters to the command's Parameters collection

For right now though, one thing at a time. Comment out the binding to th
listbox at the onset and the relations, just temporarily and see if tha
doesn't get you past the first part. If it does we can work backward fro
there. The fact that the position is moving (usually if it's the checkbo
issue it won't move) makes me think it's working but related to the listbo
and its relationships

I'll be around for a while so let me know what you come up with

HTH

Bil

--

W.G. Ryan, eMV

http://forums.devbuzz.com
http://www.knowdotnet.com/williamryan.htm
http://www.msmvps.com/WilliamRyan
http://www.devbuzz.com/content/zinc_personal_media_center_pg1.as
Greg said:
Ok, I put the bindingmanagerbase before I added the bindings. No luck.
know the position is updating b/c when I go into Debug Mode, I can view th
eqBindingManagerBase.Position in the Immediate window. It updates, but th
fields don't change. Any ideas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top