Solved

ErrorProvider Glitch

Posted on 2003-12-02
19
971 Views
Last Modified: 2007-12-19
Hi

I'm running Visual Studio .Net 2003 and I'm having a little problem with the ErrorProvider.

I have a tab control with 2 pages with many textboxes.  I validate what's in the textbox during the validating method.  The ErrorProvider works great.  It puts it's little icons besides all incorrect entries.  When the user updates the form, I call errorProvider.dispose so that it clears all the little red icons.  However, if I click on tab page 2 then come back to tab page 1, all the little red icons appear.  What am I missing?  I'm thinking that it's not disposing of all the errors.  
Any help would be greatly appreciated.
0
Comment
Question by:Tigger996
19 Comments
 
LVL 18

Expert Comment

by:testn
Comment Utility
You should clear out the error by setting the text instead of calling Dispose. Dispose will clean up the object not the text.

foreach(Control c in this.Controls)
{
    errorProvider1.SetError(c,"");
}
0
 

Author Comment

by:Tigger996
Comment Utility
What would the code be for Visual Basic?

0
 
LVL 15

Expert Comment

by:liebrand
Comment Utility
for each c as control in this.controls
   errorProvider1.seterror(c,"")
next
0
 

Author Comment

by:Tigger996
Comment Utility
I have put in the above code. However, when I click my update button,  the errors icons disappear, BUT when I click to a different tab page and come back to the first one, the error icons re-appear.  Does anyone have any ideas?

0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
If you are clearing the errors, then the icons should disappear and not come back.  If they are coming back, then you have an event that is setting them again.  Find any lines that SetError, and put a break point there, and check to see if you get there after switching tabs.
0
 

Author Comment

by:Tigger996
Comment Utility
I have put breakpoints in.  For example I have approx. 20 fields on my form.  When I tab through a couple of them, my errorprovider comes up like it should.  So in that instance, ornly 2 controls have been set with the errorprovider. When I click my update button, I run the above code (now), the icons disappear, I switch tabs, All error fields have the red icon.  But with breakpoints, the validating method dioesn't get touched.  It just kinda happens magically.

 
0
 

Author Comment

by:Tigger996
Comment Utility
A Little Addition:

After playing around, after the icons appear on their own, I edited the textbox and put in a valid entry, the validating method is called, I set the errorprovider to "", but the icon doesn't go away.
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
I have VB.NET 2003, and I haven't seen this "magical" problem with the ErrorProvider control, but I probably never got into the exact situation that you are in.
0
 

Author Comment

by:Tigger996
Comment Utility
I can handle that the errorprovider comes up on invalid fields, but when I do put a proper value in, the error provider won't disappear after I switch between tab pages and they re-appear.


0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
You're right, there is something strange going on here.  I set up a small test with just a tab control (2 pages), and a few controls, and an error provider.  When I switch tabs the error icons don't reappear.  You might want to set up this kind of test to see if it will work with only a simple set of conditions.
0
 

Author Comment

by:Tigger996
Comment Utility
Try using bound controls, I'm starting to believe that it has something to do with that.  I'm going to remove all my errorprovider statements and start from scratch.  Maybe I can see when and where it's going wrong. I'll keep you posted.
0
 

Author Comment

by:Tigger996
Comment Utility
Some more info:

1) Would upgrading to 2003 from 2002 have any differences. Because I think It was working in 2002.  I'm not sure now.

2) I've even set my errorprovider = nothing when I updated the record, and it still shows up if I swtich between tab pages.
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
1)  Since I didn't have 2002, I can't comment on any conversion problems.  My only comment would be 'Maybe'.  I have seen others have minor problems when converting from 2002, but not this problem specifically.

2)  I don't know what implication ErrorProvider = Nothing has.  If there are other references to it, the garbage collector won't dispose of the object.  How do you use the ErrorProvider specifically?  SetError?
0
 

Author Comment

by:Tigger996
Comment Utility
I tried serError(sender,""), setError(txtbox,""), setError.Dispose()

I think I've narrowed it down to the tab page.  I removed all references to the errorprovider, created a new one, and had it check on 1 field.  Once I switched tab pages after it has been set, it still came back.  Otherwise, if I stayed on the same tab page, it worked perfectly.  

So my own solution, I'm creating my own error checking/displaying class.  

So I guess my next question is, You know how the errorProvider blinks, how could I do that with my picturebox control.?

And when using the picturebox control, is the image embedded in the code so that you don't need the file sitting in the app directory somewhere and have to worry about setting the path?

3rd Is there a way to run through all picturebox controls so that I get rid of my icon?

These are pretty easy questions, I'm kinda running late on this project.  So whoever can help me make my class work the way I want, I'll reward all the points to them.

0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
Comment Utility
(1) Blinking picturebox:

Timer control:  Set interval to blink rate in the milliseconds.
Timer_Tick event:  Toggle the visible property for the picture box

(2) The image for the picture box is stored in .resx file, so it doesn't depend on the physical disk location.

(3) Looping through picture boxes:

     Dim control As Control
     Dim picture As PictureBox
 
     For Each control In Me.TabControl1.Controls

         If TypeOf control is PictureBox Then
             picture = CType(control, PictureBox)
             picture.Image = Nothing
         EndIf

     Next control
0
 

Author Comment

by:Tigger996
Comment Utility
1) How can I tell me class sub to look at a tabcontrol ?  I was just passing the form (Me). And that doesn't see what's in the tabpages.

2)Would I have to loop through each tab page and form?

Thanks for all your help, you don't know how much I appreciate it.



0
 

Author Comment

by:Tigger996
Comment Utility
Ok This is getting frustrating.  I've tried passing this, me.tabpage1.controls.  All the function see's is the groupboxes on my tab control page, not what's in the groupboxes.  Is there a way to check all controls on the WHOLE form?

0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
The Controls property only shows you the controls that it owns.  So, if you want the controls for the group box, then:

For Each control In Me.GroupBox1.Controls
0
 

Author Comment

by:Tigger996
Comment Utility
Thanks TheLearnedOne.  You were a GREAT help. Keep watching for my posts. :)  I'm still pretty new to .Net and am amazed that I have a functioning database program.  

Thanks again.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now