bound textbox text change won't save to dataset

N

njp

BlankHi,

I select a value in a bound combobox on tab 1, then I programically assign
related text to a bound textbox's text property on tab 2. I see the text in
the textbox when I view tab 2 and the textchanged event fired. However,
after I save the changes, close the form, reopen the form, the previous data
appears in the textbox, not the new data. Here's the code from the
combobox's selectedIndexChanged event:

With txtSignalOffset
.Focus()
.Text = "10"
End With

CType(sender, ComboBox).Focus()
CType(cmTerminal.Current, DataRowView).EndEdit()

Both the combobox and textbox are bound to the same datatable. If I type
data directly into the textbox there is no problem. However I want the
textbox to be read only and assigned a value by code only.

I tried editing the CType(cmTerminal.Current, DataRowView) datarow directly
but then got screwy behavior from the combobox such that it wouldn't change
its selected value - it kept bouncing back to the original value. Same thing
happened when I instead tried directly editing the datatable. This is
driving me crazy and wasting a lot of time.

Thanks for any insights you may have,
NJ
 
N

njp

Hi,

Here's the code that runs after I hit the Save button. I have to play with
it more since I'm not sure it's the best way to handle checking if changes
were made and if so then saving to the db. Currently it thinks changes have
been made when they haven't been. The current logic is additionally trying
to handle if a user makes a change to a field without going to some other
field - a trickier situation to pick up a possible data change. BTW, this is
all using a strongly-typed dataset. Also, I set all of the tab controls and
tab pages to have the same bindingcontext as the main form, to keep them in
sync.

Dim cmTerminal As CurrencyManager =
DirectCast(Me.BindingContext(dsCurrentMission.tblTerminal), CurrencyManager)

'Check if Terminal currency manager has pending change
If cmTerminal.Count > 0 AndAlso _
cmTerminal.Current.GetType() Is GetType(DataRowView) Then

Dim drv As DataRowView = CType(cmTerminal.Current, DataRowView)
If Not drv.Row.RowState = DataRowState.Detached Or DirtyTerminal Then
drv.EndEdit()
End If

If drv.Row.RowState = DataRowState.Modified Or _
drv.Row.RowState = DataRowState.Detached Then

txtLastModified.Focus()
txtLastModified.Text = System.DateTime.Now
cmTerminal.EndCurrentEdit() 'push change to dataset

End If
End If

If dsCurrentMission.HasChanges AndAlso SaveSuccess Then
Recs = daTerminal.Update(dsCurrentMission.tblTerminal)
End If

Thanks!
NJ
 
G

Guest

I am having the exact same problem. If I set a textbox programically and
update the dataset it does not update with the new data. However if I tab to
the textbox and then update the dataset it will save the new data.

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