Binding semantics when the model is changed

R

Richard Corfield

I'm having trouble with a form that is bound. The form contains
amongst other things a TextBox and some DataGridViews.

The problem is when the user enters text into the text box, then
clicks on a button to add a row to a DataGridView. Following my
company's style guide that button is on a toolbar not part of the view
itself.

What seems to happen is this:

User types text.
User clicks on button.
The button's event is fired. Value of textControl.Text is correct
at this point.
A row is added to the DataGridView
This causes a modification to the object that is bound. Some of our
code is involved here.
... which fires a PropertyChangeEvent with the name of the list
property
... which we guess causes every control on the form to reload its
data from the object
... which has the effect of rolling back the user's entry in
textControl
We then get the Validating event for textControl, but the text has
been lost.

Wasn't validation meant to be able to veto changes of focus, or is
that the problem? The button doesn't get focus to be fired, though I
thought validation was meant to be able to veto things like the OK
button being pressed. That's an aside. The main problem is the loss of
text.

We could work around it by using InvokeLater on the button to force
the events into the right order, or doing away with binding, but
neither of these sound ideal situations. I can imagine one day needing
"InvokeEvenLater" and "InvokeReallyLate" as we get into fix upon fix.
Is there a better way, or have we perhaps misunderstood something?

Thanks

- Richard
 
C

ClayB

At the start of your Toolbar button handler code, have you tried
calling the form's Validate method. This may trigger validation on the
textbox so the value is saved earlier.

===================
Clay Burch
Syncfusion, inc.
 
R

Richard Corfield

At the start of your Toolbar button handler code, have you tried
calling the form's Validate method. This may trigger validation on the
textbox so the value is saved earlier.

===================
Clay Burch
Syncfusion, inc.

Just tried it. It seems to work.

Thanks a lot!!

- Richard
 

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