ErrorProviders and How can I encapsulate business logic in typed datasets???

W

windsurfing_stew

Hi Group,

I've put business logic into my typed datasets, eg:

protected override void
OnColumnChanging(System.Data.DataColumnChangeEventArgs e)
{
// Ensure price valid
if (e.Column == this.PriceColumn)
{
if ((decimal)e.ProposedValue < 0)
e.Row.SetColumnError(e.Column, "Please ensure
that the price greater than zero");
else
e.Row.SetColumnError(e.Column, "");
}

...

base.OnColumnChanging(e);
}
}

In my windows form I've bound this typed dataset to a BindingSource,
then bound fields to that. All words well. I've also bound an
ErrorProvider to this BindingSource. I

I have two problems -

1) I can still save a record even if the red icon is shown.
2) If the focus never enters and hence never leaves the bound textbox
then this validation is never called and the user never knows.

Any ideas on how to get around this? I'm surprised MS haven't come up
with an easy solution to allow business logic to be stored in the typed
dataset and enforced reliably on at the windows forms level. Thoughts?

Stewart
 
G

Guest

If you save the record or not, when validation errors occur, that's entirely
up to you. In some scenarios, you may want to save a record with validation
errors and then correct those errors later.

A Me.ValidateCHildren method exists on the form that allows you to call the
Validation events for all child controls of the form. I think that solves
your issue number 2.

Hope this helps,

Joris
 
W

windsurfing_stew

Thanks. Unfortunately calling ValidateChildren was always returning
false, even if there were errors being set in the DataSet. It appears
that ValidateChildren only looks at calls to the Control.Validating.

Any other ideas?

I'm beginning to think that validation needs to be in the form. Pity -
I was hoping that this time the typed DataSet was going to become a
first class business object.
 
W

windsurfing_stew

Joris said:
If you save the record or not, when validation errors occur, that's entirely
up to you. In some scenarios, you may want to save a record with validation
errors and then correct those errors later.

A Me.ValidateCHildren method exists on the form that allows you to call the
Validation events for all child controls of the form. I think that solves
your issue number 2.

Hope this helps,

Joris
 
Top