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
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