Displaying datatable in datagrid while table's being filled...

V

VM

When I display data to a Windows datagrid I usually fill the underlying
table (in another class) and then, once it contains all the data, I attach
it to the grid. But there are some processes that involve large amounts of
data so the user won't be able to see anything in the grid until after the
table's already filled up (usually 40-60 secs with these large processes).
Is it possible (without changing the process of filling the table elsewhere)
to display some data in the grid while the table's filling up? I was
thinking of displaying X records every few seconds. That way the user has
something to look at.

thanks.
 
W

William Ryan eMVP

I'd spin it off into another thread (which is a good idea for all db access
if you are doing it in the same thread as the UI), put up a wait box of some
sort and go from there. You can break it into smaller queries but that's
going to slow the process overall in many instances, then again, there are a
lot of possible variables.
1) Is the query taking forever b/c it's huge (ie 10000 records) or is it b/c
it just takes a long time on the server? It it's b/c it's 10000 records,
then you may benefit from breaking it up
2) The user many not need all of that data since the grid only displays
less than 50 records at a time in most UI Scenarios. You may want to wait
for the user to scrolll down or something before getting the additional data
3) You should bind the grid to the table only once. If you clear it, then
it will appear to clear itself.If you fill it it will automatically show the
data.. In doing so you could keep filling the table with additional queries
However you are either going to freeze the ui or you'll need to synclock the
grid (you don't want multiple threads accessing the datatable without
locking it) it which will impede the effect you want.
4) What in the world is causing a query that long? That's the biggest
problem. If it's sheer number of records, then you are without a doubt
dealing with more data than the user is going to need at once. If you want
to pull 10000 records or slow, you can't expect to have a speed demon
(nothing magic about 10,000, my point is merely really large record counts.)
If the querry is taking that long to process on the server, you'll want to
figure out why and address this. Unless it's serious batch processing or
something, that's a LONG time for a query to run considering most take about
a second at most. I'd tune this up and get it running as fast as possible.

Even if you did 500 at a time, assuming that the size is the problem, you
could show the 500, then, if the user scrolls to a point that you need more
or hits a navigate button indicating more are needed, you could throw up a
wait box, grab another 500 (calling Datadapter.Fill(datatable) without clear
will append the records to the end which is what you want). Since you have
much smaller records this should be fast and a wait box should be tolerable.
You can do this until the table is filled.

The point if it's huge is that it's doubtful the user is going to use 10k
records in one immediate sitting. The phone might ring, a meeting may come
up or whatever. So anything more than he needed is wasted.

I think if you use threading correctly you can make the UI much more
responsive and they can do something else while the grid is filling. And if
you don't rebind it each time, just call .Fill on the table that the grid is
already bound to, you should be able to make this manageable.

HTH,

Bill

--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
http://www.devbuzz.com/content/zinc_personal_media_center_pg1.asp
 
V

VM

Thanks for your reply.
The process takes so long because I'm querying their own proprietary "DB"
through their API. Since the API only returns one record at a time, I
manually fill up the table with data by appending each additional row I
receive. Then I return it to the UI.
I was thinking of getting small chunks of the data at once like you
suggested, but I'm not sure how to do it. In the UI, the OK event handler
has two instructions:

_dataTableBrowse = ZMDataBrowse.ZM_getAddressDataSet(additional parms);
//this is what takes so long because it's filling the table
dataGrid_browse.DataSource = _dataTableBrowse;

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top