listbox, data binding, text boxes

G

Guest

Hello
I'm trying to run the code below, but I'm running into a problem
It is populating a listbox, based on whether or not the user enters data into a text box. If they enter something, it returns only that record, if they leave it blank, it returns all records. This works fine.
Now I have text boxes that are linked to what is displayed in the listbox. If the user enters nothing, it works fine, and if the user enters something it works fine, but if the user enters one, then the other (without restarting the program) they receive the error message: "This would cause two bindings in the collection to bind to the same property"

How can I fix this?
Thanks
ambe


Private Sub butRetrieve_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butRetrieve.Clic

lBoxCP.DataSource = Nothin
If txtCPMain.Text <> "" The

OleDbDataAdapter2.SelectCommand.Parameters("STR_CUTTING_PERMIT").Value = txtCPMain.Tex
DsCuttingPermit21.Clear(
OleDbDataAdapter2.Fill(DsCuttingPermit21
lBoxCP.DataSource = DsCuttingPermit2
lBoxCP.DisplayMember = "TDT_CUTTING_PERMIT.STR_CUTTING_PERMIT
Me.txtOArea.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.DsCuttingPermit21, "TDT_CUTTING_PERMIT.STR_OPERATING_AREA")

Els
DsCuttingPermit1.Clear(
OleDbDataAdapter1.Fill(DsCuttingPermit1
lBoxCP.DataSource = DsCuttingPermit
lBoxCP.DisplayMember = "TDT_CUTTING_PERMIT.STR_CUTTING_PERMIT
Me.txtOArea.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.DsCuttingPermit1, "TDT_CUTTING_PERMIT.STR_OPERATING_AREA")

End I

End Sub
 
K

Ken Tucker [MVP]

Hi,


Add Me.txtOArea.DataBindings.Clear before your code to bind the
textbox.

Ken
---------------
amber said:
Hello,
I'm trying to run the code below, but I'm running into a problem.
It is populating a listbox, based on whether or not the user enters data
into a text box. If they enter something, it returns only that record, if
they leave it blank, it returns all records. This works fine.
Now I have text boxes that are linked to what is displayed in the listbox.
If the user enters nothing, it works fine, and if the user enters something
it works fine, but if the user enters one, then the other (without
restarting the program) they receive the error message: "This would cause
two bindings in the collection to bind to the same property".
How can I fix this??
Thanks!
amber



Private Sub butRetrieve_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles butRetrieve.Click
lBoxCP.DataSource = Nothing
If txtCPMain.Text <> "" Then
OleDbDataAdapter2.SelectCommand.Parameters("STR_CUTTING_PERMIT").Value =
txtCPMain.Text
DsCuttingPermit21.Clear()
OleDbDataAdapter2.Fill(DsCuttingPermit21)
lBoxCP.DataSource = DsCuttingPermit21
lBoxCP.DisplayMember = "TDT_CUTTING_PERMIT.STR_CUTTING_PERMIT"
Me.txtOArea.DataBindings.Add(New
System.Windows.Forms.Binding("Text", Me.DsCuttingPermit21,
"TDT_CUTTING_PERMIT.STR_OPERATING_AREA"))
Else
DsCuttingPermit1.Clear()
OleDbDataAdapter1.Fill(DsCuttingPermit1)
lBoxCP.DataSource = DsCuttingPermit1
lBoxCP.DisplayMember = "TDT_CUTTING_PERMIT.STR_CUTTING_PERMIT"
Me.txtOArea.DataBindings.Add(New
System.Windows.Forms.Binding("Text", Me.DsCuttingPermit1,
"TDT_CUTTING_PERMIT.STR_OPERATING_AREA"))
 

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