J
Jon Skeet [C# MVP]
I've got a problem which *may* be with the Compact Framework, but may
be in the main framework as well - I'm having a very difficult time
reliably reproducing it, so I thought I'd ask here for further advice.
The principle objects involved are:
o A datarow, with a column in it (call it X)
o A row handler which has some validation logic in it
o A control (derived from ComboBox) with a bound property in it, bound
to column X
We go into the form fine - the possible values and the default value
are all set up appropriately, and the user can select one of the
values. The property gets changed correctly.
When the user hits the OK button, the row handler is called. It
validates the proposed value. This is where the problems occur. The
proposed value is acceptable, and the row handler correctly detects
that. It then sets the row error for the column to null, to make sure
that if there were any previous errors, they are cleared.
Unfortunately, this fires a record changed event, and *sometimes* the
property value in the control is then set back to the row's "current"
value. It doesn't happen every time, and I'm having a hard time working
out what's going on there - any suggestions for a direction in which to
turn are warmly welcomed.
It's a slight shame that the record changed event fires in the first
place, and we could avoid it, although I don't think we should have to.
An error is cleared by setting it to either null or an empty string,
but GetColumnError always returns an empty string if there's no error -
so to naive code, setting the value to null *is* changing it, even
though there's no actual change in any data including the value of
GetColumnErrror afterwards. Even though we can avoid it here, we may
not be able to elsewhere, and sometimes there *will* have been an error
previously - so we need to understand why the old value is being shown
sometimes.
Has anyone else run into this before?
be in the main framework as well - I'm having a very difficult time
reliably reproducing it, so I thought I'd ask here for further advice.
The principle objects involved are:
o A datarow, with a column in it (call it X)
o A row handler which has some validation logic in it
o A control (derived from ComboBox) with a bound property in it, bound
to column X
We go into the form fine - the possible values and the default value
are all set up appropriately, and the user can select one of the
values. The property gets changed correctly.
When the user hits the OK button, the row handler is called. It
validates the proposed value. This is where the problems occur. The
proposed value is acceptable, and the row handler correctly detects
that. It then sets the row error for the column to null, to make sure
that if there were any previous errors, they are cleared.
Unfortunately, this fires a record changed event, and *sometimes* the
property value in the control is then set back to the row's "current"
value. It doesn't happen every time, and I'm having a hard time working
out what's going on there - any suggestions for a direction in which to
turn are warmly welcomed.
It's a slight shame that the record changed event fires in the first
place, and we could avoid it, although I don't think we should have to.
An error is cleared by setting it to either null or an empty string,
but GetColumnError always returns an empty string if there's no error -
so to naive code, setting the value to null *is* changing it, even
though there's no actual change in any data including the value of
GetColumnErrror afterwards. Even though we can avoid it here, we may
not be able to elsewhere, and sometimes there *will* have been an error
previously - so we need to understand why the old value is being shown
sometimes.
Has anyone else run into this before?