dotnet windows forms databinding:
Problem:
I have two DataTables linked as parent and child via BindingSources, where
the child BindingSource uses the parent BindingSource as DataSource and the
foreign key relation as DataMember in order to provide for proper observation
of parent child relations in the form.
When I want to create a new child record on an existing parent record, I
press '+' on the child BindingNavigator. The problem occurs when, in this
situation, without doing anything else, I press the MovePrevious symbol on
the BindingNavigator. A "NoNullAllowedException" is thrown, and the whole
form is stopped.
Interpretation: On moving to the new child record, this record is
automatically provided with the key entry it has in common with the existing
parent record. Given the fact that no other change occurs on the child
record, it is incomplete insofar the second key entry (that is necessary in
order to distinguish different childs belonging to the same parent) remains
empty. So when I move away from this record, the underlying BindingSource
tries to save it and finds this second key to be NULL.
Question: How can I deal with this (rather common) situation? The normal
behaviour of the BindingSource in the situation described should be: discard
new records that the user moves to but doesn't touch by making any change.
How can the BindingSource be made to understand that new records whose only
changes have been done by the underlyinig BindingSource functionality, should
be discarded as well?
This is what I already tried without success: using RowChanging and
RowChanged events of the DataTable (they are only called after the
exception); using DataError (not called at all) or other events of the
BindingSource.
Thanks for any hint! Axel Hecker.
PS: It seems that another post on this forum from August 8 raises the same
point. It is titled "How do I handle exceptions that are thrown during a move
method of the BindingNavigator" by "Peet", but without answer.
Axel Hecker