Problem updating object behind bindingSource

S

Simon

Hi folks,

I have an form where there are two text boxes bound to an object via a
BindingSource. I have implemented a document save function via Binary
Serialization that writes the underlying object to disk.

The problem is, if a user edits the data in one of the text boxes but
DOES NOT leave the text box before selecting the Save menu item, the
change in the text box is not replicated back to the object behind the
form (the object that is serialized). Hence when I reload the document
the Deserialized data contains the contents of the textbox before the
user changed it. If the user leaves the textbox first, everything is fine.

My thinking is that I need to force the form to propagate its current
state back to the object before serializing, but would take some advice
on the best way to do this.

I appreciate this is not strictly an ADO.NET question but figured that
being a data binding issue, someone on here might be able to help.

Many thanks in advance.

Simon
 
B

Bart Mermuys

Hi,

Simon said:
Hi folks,

I have an form where there are two text boxes bound to an object via a
BindingSource. I have implemented a document save function via Binary
Serialization that writes the underlying object to disk.

The problem is, if a user edits the data in one of the text boxes but DOES
NOT leave the text box before selecting the Save menu item, the change in
the text box is not replicated back to the object behind the form (the
object that is serialized). Hence when I reload the document the
Deserialized data contains the contents of the textbox before the user
changed it. If the user leaves the textbox first, everything is fine.

My thinking is that I need to force the form to propagate its current
state back to the object before serializing, but would take some advice on
the best way to do this.

Call BindingSource.EndEdit() before you serialize the object.

hth,
Greetings
 
S

Simon

Actually Bart, this hasn't solved it.

It seems to have to do with the textbox still having the focus. Seems
the underlying datasource is not updated until the textbox loses focus.
Calling BindingSource.EndEdit() hasn't made any difference if I don't
leave the textbox before select Save from the menu.

I'm thinking that I need to code in "losing the focus" but just wondered
if there is a more elegant way of doing this.

Cheers

Simoin
 
S

Simon

Sorry scratch that .. I'm an idiot. Was a mistake in my logic. Works
just fine.

Thanks again

Simon
 

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