Changing a text boxes value (from code) of a data bound text box does not work

  • Thread starter Thread starter Joshua Ellul
  • Start date Start date
J

Joshua Ellul

Hi There,

I've created a form with several databound textboxes. One of the textbox's
text is filled in programatically (through code). The problem is that if i
change the value of this text box say txt1 and then tab through the other
textboxes, the original value of txt1 will appear in txt1 and not the value
that I have just input.

Any ideas?

Josh
 
Can you post the code snippet? Are you using a BindingContext or a
BindingManager? When does the test return to its original value,
immediately upon leaving the textbox, or when you navigate to another record
and then come back? If you are using a StronglyTyped dataset and input data
that it doesn't like, I believe it will simply reject the changes you just
made as soon as you leave the control. Could this be the problem?

Let me know, hopefully we can figure it out.

Bill
 
Hi William Ryan,

Basically I am setting the text box to either nullstring or else a new
imagepath:

The dataset is set up as follows:
myCon = New OleDb.OleDbConnection(DBStr)
mAdapter = New OleDb.OleDbDataAdapter("Persons", myCon)
myAdapter.Fill(myDS, "Persons")
Dim myBuilder As New OleDb.OleDbCommandBuilder(myAdapter)
myAdapter.UpdateCommand = myBuilder.GetUpdateCommand
myAdapter.InsertCommand = myBuilder.GetInsertCommand
myAdapter.DeleteCommand = myBuilder.GetDeleteCommand
myCon.Close()

I am adding the binding as follows:
txtImagePath.DataBindings.Add("text", myDS, "Persons.ImagePath")

When the user wants to change picture the following is done:
txtImagePath.text = NewPath

And when the user removes the picture the following:
txtImagePath.text = ""

The value of txtImagePath changes. The focus is never in the txtImagePath
text box (as it is filled in automatically). The next time that one of the
other bound control's focus is lost, txtImagePath changes.

I've just noticed that if the focus is in txtImagePath then the new value
will not be lost. I imagine that the dataset is being updated upon the
control losing focus. Is this necessary? Or is there another way that the
dataset could be updated?

Regards,

Josh
 
Back
Top