Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

Never ascribe to malice that which is adequately explained by incompetence. - Napoleon Bonaparte
  • Moderators
Posted
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.
Visit...Bassic Software
  • *Experts*
Posted

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]

Posted

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. ;)

Never ascribe to malice that which is adequately explained by incompetence. - Napoleon Bonaparte
  • *Experts*
Posted

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

"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
Posted
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?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...