Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2009
  • Last Modified:

Visual C# - How to Refresh datagrid, and other items when datagrid is populating.

Greetings Experts,

Ok, I have a datagrid that I populate with network information. But while the data is being gathered for the datagrid, the form seems hung, which of course it is not, it just isn't repainting. Then when the datagrid has everything it needs, bam! everything shows up, and looks great.

This includes a animation of sorts that I've created to show that the program is actually still working (processsing) which does nothing more then cycle through 8 images to show motion....

But when the datagrid is gathering info, nothing refreshes at all.

I have tried starting a "timer" prior to the datagrid call, where in the timer, it has a refresh of the specifc picturebox's that I want to refresh, (ie. picMyPic1.refresh();) but that didn't work to refresh the "animation" while the datagrid was working on gathering the info.

I also tried just doing a refresh(); on a timer, to just refresh the whole form, again, no dice.

I've also tried putting refresh events into the animation itself (which is on a timer that cycles through the 8 images), but again, no dice...

So, the Q is... how do I activly refresh the screen so that it doesn't look like my app is hung while my datagrid is searching and building it's data.

  • 3
1 Solution
Start animation using a different thread. You need to use the concept of Threading here. The problem is happening because the DataGrid and the Animation are using the same thread.

After the line where you fill the DataGrid, use:

MiShepsAuthor Commented:
I was guessing that I would have to start the animation in another thread, but was hoping it would be something easier. I tried the DoEvents(); but it didn't work.

Do you have an example of how I could start the animation in a second thread?

Well, I don't have idea on how it will work on the same Form. Probably opening another Form with animation is good. If you open a small popup Form with the animation, then that can solved the problem. For this see the following link:


Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now