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

Posted on 2008-11-03
Last Modified: 2013-12-17
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.

Question by:MiSheps
    LVL 8

    Expert Comment

    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:


    Author Comment

    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?

    LVL 8

    Expert Comment

    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:
    LVL 8

    Accepted Solution


    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    In my previous article ( we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
    This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    This video discusses moving either the default database or any database to a new volume.

    745 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

    14 Experts available now in Live!

    Get 1:1 Help Now