|
|
ErrorWarnInfoProvider object
Last post 07-30-2008, 2:09 PM by reagan123. 28 replies.
-
10-04-2007, 2:18 PM |
-
KKoteles
-
-
-
Joined on 06-06-2006
-
Jacksonville, FL
-
Posts 48
-
Points 730
-
|
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 |
-
ajj3085
-
-
-
Joined on 05-05-2006
-
Vermont
-
Posts 2,536
-
Points 38,705
-
|
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 |
-
KKoteles
-
-
-
Joined on 06-06-2006
-
Jacksonville, FL
-
Posts 48
-
Points 730
-
|
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 |
-
ajj3085
-
-
-
Joined on 05-05-2006
-
Vermont
-
Posts 2,536
-
Points 38,705
-
|
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 |
-
KKoteles
-
-
-
Joined on 06-06-2006
-
Jacksonville, FL
-
Posts 48
-
Points 730
-
|
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-05-2007, 7:06 AM |
-
ajj3085
-
-
-
Joined on 05-05-2006
-
Vermont
-
Posts 2,536
-
Points 38,705
-
|
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 |
-
KKoteles
-
-
-
Joined on 06-06-2006
-
Jacksonville, FL
-
Posts 48
-
Points 730
-
|
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 |
-
KKoteles
-
-
-
Joined on 06-06-2006
-
Jacksonville, FL
-
Posts 48
-
Points 730
-
|
Re: 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
|
|
-
10-29-2007, 6:42 PM |
-
RockfordLhotka
-
-
-
Joined on 04-19-2006
-
Eden Prairie, MN, USA
-
Posts 3,394
-
Points 57,450
-
|
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 |
-
KKoteles
-
-
-
Joined on 06-06-2006
-
Jacksonville, FL
-
Posts 48
-
Points 730
-
|
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,
|
|
-
10-31-2007, 10:24 AM |
-
RockfordLhotka
-
-
-
Joined on 04-19-2006
-
Eden Prairie, MN, USA
-
Posts 3,394
-
Points 57,450
-
|
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 |
-
Tbot155
-
-
-
Joined on 11-02-2007
-
-
Posts 4
-
Points 65
-
|
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 |
-
KKoteles
-
-
-
Joined on 06-06-2006
-
Jacksonville, FL
-
Posts 48
-
Points 730
-
|
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 |
-
Tbot155
-
-
-
Joined on 11-02-2007
-
-
Posts 4
-
Points 65
-
|
Re: ErrorWarnInfoProvider object
Thanks Ken. Great work so far. Looking forward to seeing what you come up with.
|
|
Page 1 of 2 (29 items)
1
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. Why donate?
|
|
|