Gladimir Posted March 30, 2003 Posted March 30, 2003 I have a fairly long loop as I process records in a database table. In that loop, I update the Text properties of a few labels controls, but I only get to see the updates made for the last record when all the processing is done. How do I go about refreshing/updating the controls on Form1? Quote Never ascribe to malice that which is adequately explained by incompetence. - Napoleon Bonaparte
Moderators Robby Posted March 30, 2003 Moderators Posted March 30, 2003 put a DoEvents inside your loop, but keep in mind that the user can click/use other controls on the form during the loop, so you may want to disable some controls untill you finish. Quote Visit...Bassic Software
*Experts* Volte Posted March 30, 2003 *Experts* Posted March 30, 2003 If you use an Application.DoEvents, inside the loop, it will allow other messages (e.g. painting to get through). You better disable or hide the necessary controls though, because your user will still be able to click on buttons, which can really mess things up. [edit]D'oh![/edit] Quote
Gladimir Posted March 30, 2003 Author Posted March 30, 2003 Worked... The Application.DoEvents worked perfectly. Good advice on disabling unnecessary controls, but this is a status form for my own benefit; I can screw my programs up quite well without buttons. ;) Quote Never ascribe to malice that which is adequately explained by incompetence. - Napoleon Bonaparte
*Experts* Nerseus Posted April 1, 2003 *Experts* Posted April 1, 2003 You can also use "this.Refresh()" (in C#) or "Me.Refresh()" (in VB.NET). This will cause a repainting of the form and all of it's controls but won't let any other windows messages get through (such as button clicks). You can also use the Refresh method on any single control, such as the TextBox or Label that you're updating. But you may see some strange artifacts by doing this - such as a form that turns ALL battleship grey except the individual controls you're Refreshing. I only mention this becaus calling "this.Refresh" may provide unwanted flicker if you have a large form with a lot of controls. Of course, this is only for you for now. But if it ever goes to another user and they're not as forgiving as you, be ready to change a line or two of code :) -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Azrael Posted April 1, 2003 Posted April 1, 2003 Would it not be better to spawn a thread and do the heavy db work in that? Then when a ui component is changed marshal a call to the ui event q thread with BeginInvoke? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.