cjard
Well-known member
- Joined
- Apr 25, 2006
- Messages
- 7,081
- Programming Experience
- 10+
Suppose I have a form where a control is allowed to edit the primary key of some datatable. Binding is through a bindingsource.
You can change the value so that it collides with another primary key already present in the table. As soon as EndEdit() is called (however so), a ConstraintException occurs and the proposed changes are destroyed.
This in itself is not a problem; the problem is that the typing I did in the controls, is still there.. If I edited the PK from "one" to "two" but "two" was already present, then a ConstraintException has occurred and the datatable still says "one" but the control now says "two".
There are two courses of action here:
Reset the controls to show the "last known good" values - i.e. the Current values in the datarow. This would basically involve having the controls re-query/refresh the underlying data. How do we do this? (binding is normally two way - if I put a button on the form that sets a column in the the current row to a new value, then the change is immediately reflected in the textbox. In case of ConstraintException, it seems the binding is not two way)
Be more clever; return the user to the state before EndEdit was called - the controls still show the new values, and ask the user to pick a different PK. How do we do this?
You can change the value so that it collides with another primary key already present in the table. As soon as EndEdit() is called (however so), a ConstraintException occurs and the proposed changes are destroyed.
This in itself is not a problem; the problem is that the typing I did in the controls, is still there.. If I edited the PK from "one" to "two" but "two" was already present, then a ConstraintException has occurred and the datatable still says "one" but the control now says "two".
There are two courses of action here:
Reset the controls to show the "last known good" values - i.e. the Current values in the datarow. This would basically involve having the controls re-query/refresh the underlying data. How do we do this? (binding is normally two way - if I put a button on the form that sets a column in the the current row to a new value, then the change is immediately reflected in the textbox. In case of ConstraintException, it seems the binding is not two way)
Be more clever; return the user to the state before EndEdit was called - the controls still show the new values, and ask the user to pick a different PK. How do we do this?