views:

252

answers:

2

I am writing a program in VB.Net to manage text messages sent through an API. It allows you to view messages in a datagridview and filter by date, sent/unsent etc...

To load the messages I'm executing an SQL statement and retrieving a DataTable which then gets set as the DataSource for my DataGridView control.

The problem is that depending on the filters selected the user could be selecting a lot of records and it would take some time for the DataSource to update. I want to inform the user of this load time by providing a progress bar or label of some kind.

I have used progress bars before when looping through data but this is loading it all at once. I thought of displaying a label when the user clicks to load the data and then hiding it when the data is loaded. But this happens instantaneously even when the data is still loading.

Is there an event on the DataGridView I can use perhaps? Something like .DataSourceLoadStart and .DataSourceLoadFinished.

I know I'm just making those events up... but hopefully it makes it clearer as to what I want.

+1  A: 

You could set the label to be visible when load is clicked and try the: DataGridView.DataBindingComplete Event to hide it, this event gets called when the binding is complete.

MSDN Link - DataBindingComplete

Tanner
This does what it should. I think the problem is making the label visible on the click of the load button.At the moment it goes... click > show loading label > load messages > databinding complete ( hide message again )But the label wont show while the data is loading. It shows the label once the DataGridView is populated and then immediately hides it again. Even though my code goes like:<pre>lblLoading.visible = trueLoadMessages()</pre>So it should be showing the label first... ???
Banford
Add: Application.DoEvents() after the call to show the label, that way it will prioritise the showing of the label before it goes off to load the messages
Tanner
MSDN Link: Doevents(): http://msdn.microsoft.com/en-us/library/system.windows.forms.application.doevents.aspx
Tanner
After adding DoEvents() and using the DataBindingComplete() method it all works exactly how I want it to. Thanks for your help.
Banford
A: 

A little off topic but... I wonder if you could attach a AJAX update panel with activity/loading image to a gridview? I don't think I've ever seen it done but here's a great application for it.

rlb.usa
I would, and have previously used this method to achieve similar results. But this is for a desktop app, sorry if I didn't make that clear.
Banford