Click here to Skip to main content
15,742,357 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)

In My windows application I am loading huge data in Datagridview ( using data source dgv.datasource=ds.Table(0) ),it is taking more time load so user cant understand it is loading or application hanged so i want to display the loading status in progressbar or something which user can understand that data is loading....

if possible please give me sample code....

Please Help me....
Updated 26-Nov-12 23:54pm

Try this as an example.

Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork

    'Do NOT (ever) refer to form controls from this method
    'Keep it self contained

    'Add your background code

    'As you pass through each loop in your long runtime method do something like this
    BackgroundWorker1.ReportProgress(CInt((countsofar / totalofthingstodo) * 100))

End Sub

Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As System.Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
    'Only ever refer to form controls from this method
    ProgressBar1.Value = e.ProgressPercentage
End Sub

Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As System.Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
    ProgressBar1.Value = ProgressBar1.Minimum
End Sub

Where it says ''Add your background code', use that to fill a DataSet (created programatically, not a form control) and once the background worker has finished you can attach the DataSet to the DataGridView.

Share this answer
Do the DataGridView Loading via a BackgroundWorker, you'll need to populate an object you create in the BackgroundWorker thread rather than the DGV directly (since you shouldn't interact with the UI thread from the BackgroundWorker thread) and then copy the data to the DGV when it finishes. Use something like this[^] as your progress bar and the ReportProgress functionality of the BackgroundWorker to update it to show progress and a message.

Share this answer
bayramchik 15-Mar-13 0:17am    
Could you please provide sample code. Thanks in advance
Mike-MadBadger 15-Mar-13 3:25am    
See the following answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900