Troubleshooting the ErrorProvider?

Troubleshooting the ErrorProvider?

Old forum URL: forums.lhotka.net/forums/t/3771.aspx


rsbaker0 posted on Wednesday, October 24, 2007

I'm wondering in general how one goes about troubleshooting problems with the ErrorProvider control.

I've added some business rules to my bound objects, and the rules are working great. The object is flagged as invalid and CSLA throws an exception if you try to save it.

However, the ErrorProvider might as well not even be there. I've looked at the ErrorProvider designer code and compared to ProjectTracker, and it looks almost identical.

Also interesting is that when doing "in cell" editing with an ERLB bound to a DevExpress XtraGrid, it doesn't show the errors either. However, if the rule malfunctions and throws an exception, the DevExpress grid shows that clearly with it's own ErrorProvider control.

KKoteles replied on Wednesday, October 24, 2007

I've never had an issue with it...  You have a bindingSource control on your form correct?  You set the DataSource property of the bindingSource to your CSLA object, the data bindings of all your controls are set to the bindingSource and the appropriate text property, and the DataSource of the errorProvider itself is set to the bindingSource correct?

Did you add the BindingSourceRefresh control as well?  Make sure the new property that is added to your bindingSource (ReadvaluesOnChange) is set to "true".

Not sure what else to check.

Ken 

rsbaker0 replied on Thursday, October 25, 2007

KKoteles:
I've never had an issue with it...  You have a bindingSource control on your form correct?  You set the DataSource property of the bindingSource to your CSLA object, the data bindings of all your controls are set to the bindingSource and the appropriate text property, and the DataSource of the errorProvider itself is set to the bindingSource correct?

*Exactly* -- and the bindings themselves work like a champ. Moreover, the broken rules collection of the bound object is updated as soon as you leave the field with the bad value, but the error provider is silent.

This is why I'm mystified.

So, when you're working with a "black box" like the ErrorProvider and it simply doesn't work once you've deskchecked everything, how do you go about figuring out why it's not working? Is there some event you can hook?  Is there some debuggable ErrorProvider-like control out there that you can substitute?

KKoteles replied on Thursday, October 25, 2007

Take a look at this thread:

http://forums.lhotka.net/forums/thread/18041.aspx

I created an ErrorWarnInfoProvider that 'wraps' the ErrorProvider and allows for displaying warnings and informational details associated with a CSLA object.  It might give you some insight into what the ErrorProvider itself is trying to use.  There are a couple of bugs I fixed since I last posted, but no one seemed interested.  If you are interested in the latest version (it fixes a bug where it now recurses through controls that contain controls) let me know and I can update it again. If that doesn't help, then you can try this site:

http://www.aisto.com/roeder/dotnet/

By using reflector you can see exactly what ErrorProvider is doing internally.  You can't debug it (as far as I know), but at least you can get an idea of what it is doing.

Ken

rsbaker0 replied on Thursday, November 01, 2007

KKoteles:

...There are a couple of bugs I fixed since I last posted, but no one seemed interested.  If you are interested in the latest version (it fixes a bug where it now recurses through controls that contain controls) let me know and I can update it again. ...

Yes, we definitely use nested controls, so I'd be interested in the related fixes. Thanks.

ajj3085 replied on Thursday, October 25, 2007

I'm actually getting this now as well; the bindings work, but the provider doesn't show the error.

I did fix an issue recently where the rule was bound to a child collection and via dependant properties, a specific property on the root object.  Moving the rule to the root object itself resolved that issue.

I'm having the same problem now in another compoent; I actually have a control which allows editing of a root's child BO and the provider isn't working.  Don't know why though.. going to investiage.

ajj3085 replied on Thursday, October 25, 2007

Well, I've been able to confirm it's not a problem with having an ErrorProvider on a user control.  Still looking into it though.

ajj3085 replied on Friday, October 26, 2007

I don't know if this helps anyone else, but I found the problem with my ErrorProvider.

It seems that Description is not being set.  This is my rule method:

        private static bool StateMaxLength(
            DocumentContact target,
            RuleArgs e
        ) {
            bool result;

            if ( target.contactType == DocumentContactType.BillTo ) {
                result = CommonRules.StringMaxLength(
                    target,
                    new CommonRules.MaxLengthRuleArgs(
                        "State",
                        2
                    )
                );
            }
            else {
                result = true;
            }

            return result;
        }

So the problem is that I'm creating new rule arguments and so the one passed in is never changed.  Opps.

Copyright (c) Marimer LLC