CSLA .NET

From Rockford Lhotka's Expert C# 2005 and VB 2005 Business Objects books

Welcome to CSLA .NET Sign in | Join | Help
in Search

ErrorWarnInfoProvider object

Last post 05-25-2008, 10:10 PM by akhirudin. 26 replies.
Page 1 of 2 (27 items)   1 2 Next >
Sort Posts: Previous Next
  •  10-04-2007, 2:18 PM 18041

    ErrorWarnInfoProvider object

    I've always liked the idea of the ErrorProvider; however, all it displays are the errors.  I couldn't find anything else so I tried my hand at extending it.

    If you take a look at the code in my attachment (don't forget to update the references for CSLA before you try to compile!), you can see I've created an ErrorWarnInfoProvider object that that displays all three levels of severity for the BrokenRulesCollection.  I like it a lot, but I can't figure out how to get it to "hook" itself to the appropriate events automatically - so I took a short cut.  Unfortunately that means you need to add the following line (or something like it) within the associated form's constructor:

    this.errorWarnInfoProvider1.Initialize(this.Controls);

    Obviously there are many areas open for improvement (like being able to set each icon as well as setting it's respective offset from the base ErrorProvider icon, etc); however, I was hoping someone might be able to lead me in the right direction for both trying to tie this into the control events automatically (without needing the Initialize method).

    Any suggestions / recommendations?

    Thanks,

    Ken

  •  10-04-2007, 2:52 PM 18045 in reply to 18041

    Re: ErrorWarnInfoProvider object

    Hmm... well the standard one does this:
    System.Windows.Forms.ErrorProvider( this.components )

    perhaps that helps?
  •  10-04-2007, 3:25 PM 18048 in reply to 18045

    Re: ErrorWarnInfoProvider object

    I realize that the constructor is passed a container object:

            public ErrorWarnInfoProvider(IContainer container)

    I’m not exactly sure what that container object is.  I do know it is not the form itself – and I can’t figure out how to “back out” from the component’s within the container (of which my object is one) to get back to the form.  The container object contains components, but it does not contain controls.

    I need to be able to get to the Control.ControlCollection of the form in order to set the events correctly.

    More ideas?

    Ken

  •  10-04-2007, 3:55 PM 18050 in reply to 18048

    Re: ErrorWarnInfoProvider object

    Did you create an extender control?  Because each control that interacts with errorprovider has something like this in the .designer file..

    ErrorProvider.Somemethod( Control, true ); // Or false, if the provider should ignore it.

    I can't remember what Somemethod is. and its time to go home :-)
  •  10-04-2007, 4:23 PM 18053 in reply to 18050

    Re: ErrorWarnInfoProvider object

    Hmmm.  Maybe that is where I took a wrong turn.  I ended up creating a Component Class – because that is what I thought the ErrorProvider object was.  I don’t see extended control as an option (obviously I’m new at creating these); however, there is Inherited User Control.  I didn’t think the ErrorProvider was a control though since technically it doesn’t show up on the form (but rather down in the bottom area).

     

    There is very little in my .designer file.  My Component Class just inherits System.Windows.Forms.ErrorProvider, IExtenderProvider

     

    Do I need to start from scratch?  Maybe it will look better in the morning...

  •  10-04-2007, 8:28 PM 18054 in reply to 18053

    Re: ErrorWarnInfoProvider object

    It does need to be an extender control. Look at Chapter 5, at the ReadWriteAuthorizer and BindingSourceRefresh controls in CSLA itself for some information on creating extender controls.
    Rocky
  •  10-05-2007, 7:06 AM 18060 in reply to 18053

    Re: ErrorWarnInfoProvider object

    That's fine; you just need to implement IExtenderProvider.  Rocky's code should prove as a good example, he has the ReadWriteAuthorization component.
  •  10-05-2007, 4:06 PM 18083 in reply to 18054

    Re: ErrorWarnInfoProvider object

    I finally figured out and solved my problem!  Thanks ajj3085 and Rocky for your help.  (It turns out that when I originally started this endeavor I started with a printout of Rocky’s ReadWriteAuthorization.cs; however, I still couldn't quite figure things out at that time.)  

    Initially, I was trying to bind my internal Validation_Event to the either the bound control’s KeyUp event (when it’s binding.DataSourceUpdateMode == DataSourceUpdateMode.OnPropertyChanged) or the control’s Validated event (when it’s binding.DataSourceUpdateMode == DataSourceUpdateMode.OnValidation) from within the constructor of my control.  The problem here is that the object’s ContainerControl is null at this point – so there is no way to get any information from the Form that the control has been placed on.  I needed something else to be able to get the information later in the object’s lifecycle.

    The only thing I knew that needed to be set was the DataSource property; however, since I was inheriting from the ErrorProvider that property already existed.  The solution was to force my object to get the DataSource property – and then pass that value to the base object.  The “trick” here was to add the keyword “new” to the property in order to hide the base object’s property.  Just when I thought I had it figured out, I ran into another problem.  At the time the DataSource property value is set, the object’s ContainerControl is populated; however, its Controls collection is still empty.  OK, somehow I need to delay even further.  The way I was able to do this was to create an EventHandler and tie it to the object’s ContainerControl.BindingContextChanged event.  It just happens that by the time the BindingContextChanged event is fired – the ContainerControl.Controls collection is populated.  At this point, I am home free and I just need to bind to each control’s KeyUp or Validated event like I did before.

    The attached control should be “safe” for all BindingSources; however, the warning and information features will only function if the bound object is a Csla.Core.BusinessBase object – because those are the only ones I know how to extract.  I’ve included the updated files as an attachment.  Again, don’t forget to set your reference to your Csla.DLL.  I hope someone finds this useful!

    Enjoy,

    Ken

  •  10-29-2007, 4:18 PM 18777 in reply to 18083

    Re: ErrorWarnInfoProvider object

    Attachment: Example.Utility.zip

    I've attached the latest version.  I had a request so I thought I'd update it.  There are two things I improved.  Initially it did not take into account controls within controls (like textboxes, etc within tabs).  Additionally, when I cancelled an edit on an object it was not clearing the warnings and information items.  I fixed that.

     

    Enjoy,

    Ken

  •  10-29-2007, 6:42 PM 18783 in reply to 18777

    RE: ErrorWarnInfoProvider object

    Are you willing to put this into CSLAcontrib? That may make it more discoverable for people who want to use it?

     

    Rocky

     

    From: KKoteles [mailto:cslanet@lhotka.net]
    Sent: Monday, October 29, 2007 4:19 PM
    To: rocky@lhotka.net
    Subject: Re: [CSLA .NET] ErrorWarnInfoProvider object

     

    I've attached the latest version.  I had a request so I thought I'd update it.  There are two things I improved.  Initially it did not take into account controls within controls (like textboxes, etc within tabs).  Additionally, when I cancelled an edit on an object it was not clearing the warnings and information items.  I fixed that.

     

    Enjoy,

    Ken




    Rocky
  •  10-29-2007, 7:54 PM 18787 in reply to 18783

    RE: ErrorWarnInfoProvider object

    Rocky,

     

    That would be great.  I haven’t spent too much time on the CSLAcontrib portion of the web site.  If that is the best place, then great.  If you would even want to add it along with ReadWriteAuthorization, that would be great too!

     

    Is there anything I need to do in order to put it into CSLAcontrib?

     

    Thanks,

    Ken Koteles (K2)

  •  10-31-2007, 10:24 AM 18861 in reply to 18787

    RE: ErrorWarnInfoProvider object

    Ideally you’d put it into CSLAcontrib yourself, especially if you have any plans to alter it or update it going forward.

     

    If you don’t want to do that, I can add it to the repository for you, but that won’t allow you to do any updates over time.

     

    If you want to use the repository directly, just create an account on www.codeplex.com and email me your user id. I’ll make you a contributor on the site so you have read/write access to the repository.

     

    The site uses TFS behind the scenes, so to get code in/out you need to have a TFS client installed. Microsoft has a free one you can download, that integrates with VS 2005 (and soon 2008). I believe there’s also a client on codeplex that integrates with the Windows shell much like TortoiseSVN – but I haven’t had time to go find that yet.

     

    Rocky

     

     

    From: Kenneth Koteles [mailto:cslanet@lhotka.net]
    Sent: Monday, October 29, 2007 7:55 PM
    To: rocky@lhotka.net
    Subject: RE: [CSLA .NET] ErrorWarnInfoProvider object

     

    Rocky,

     

    That would be great.  I haven’t spent too much time on the CSLAcontrib portion of the web site.  If that is the best place, then great.  If you would even want to add it along with ReadWriteAuthorization, that would be great too!

     

    Is there anything I need to do in order to put it into CSLAcontrib?

     

    Thanks,

    Ken Koteles (K2)
    (904) 220-0118

     

    From: Rockford Lhotka [mailto:cslanet@lhotka.net]
    Sent: Monday, October 29, 2007 7:43 PM
    To: KKoteles@comcast.net
    Subject: RE: [CSLA .NET] ErrorWarnInfoProvider object

     

    Are you willing to put this into CSLAcontrib? That may make it more discoverable for people who want to use it?

     

    Rocky

     

    From: KKoteles [mailto:cslanet@lhotka.net]
    Sent: Monday, October 29, 2007 4:19 PM
    To: rocky@lhotka.net
    Subject: Re: [CSLA .NET] ErrorWarnInfoProvider object

     

    I've attached the latest version.  I had a request so I thought I'd update it.  There are two things I improved.  Initially it did not take into account controls within controls (like textboxes, etc within tabs).  Additionally, when I cancelled an edit on an object it was not clearing the warnings and information items.  I fixed that.

     

    Enjoy,

    Ken

     

     




    Rocky
  •  11-15-2007, 9:01 AM 19208 in reply to 18777

    Re: ErrorWarnInfoProvider object

    Thanks for posting this control. I've been looking for something like this.

    I do have one question though. When changing one property causes another property to be valid, the 'information' and 'warning' icons on the newly valid property are not cleared. When I run the same test with the severity set to 'error' it works fine, but when it's set to 'information' or 'warning' I need to physically cause validation (by tabbing out of a textbox, etc) to cause the icon to dissappear.

    Am I doing something wrong?

    Thanks

  •  11-16-2007, 8:44 AM 19231 in reply to 19208

    Re: ErrorWarnInfoProvider object

    Tbot155,

    No - you are not doing anything wrong.

    The reason the 'error' icon is working correctly is because underneath my control is an actual ErrorProvider - and it is working like it always had.  The 'problem' is that for the other two icons I am hooking to change events off the bound control.  In your case, with dependant properties - control2 is changing and the validation / business rule violations are cleared for control1 as a result.  My problem is that control1 didn't change; therefore, I don't have anyway (right now anyway) to notify my control that control1 needs to have its icons updated.

    Looks like I have more work to do...  I've been a little tied up. Hopefully I will get this control into CSLAContrib shortly.  After that, I'll try to spend some time to see if I can't figure out a way to keep my control 'aware' of the changes to the business object itself and not just the controls bound to it... 

    Thinking out loud...  Seems like I'll need to keep an internal array of all the bound controls - and when any one of them changes, then check / reverify all the others as well.  Have to make sure this isn't a hit on performance too.  Maybe there is a way to store a count of broken rules for each bound control - then only address the 'non-triggering' controls if their broken rule count changes.  Hmmm - need to make sure I address newly broken rules and not just cleared rules.

    I've got some ideas.  I'll see what I can come up with.  Thank you for the feedback!!!

    Ken

  •  11-16-2007, 11:14 AM 19243 in reply to 19231

    Re: ErrorWarnInfoProvider object

    Thanks Ken. Great work so far. Looking forward to seeing what you come up with.

Page 1 of 2 (27 items)   1 2 Next >
View as RSS news feed in XML

Please contact Magenic for your .NET consulting and CSLA .NET mentoring needs.
Please consider making a donation to help support the ongoing development of CSLA .NET.

Make donation through PayPal - it's fast, free and secure!
Why donate?
Powered by Community Server, by Telligent Systems