DataGridView responsiveness when adding rows

mrdippy

Member
Joined
Mar 27, 2008
Messages
9
Programming Experience
5-10
I have windows form based utility that cranks out a few hundred thousand rows of mock data as a .CSV file. I'm simplifying a bit, but I want to log various activities as this windows form does its thing producing all these rows.

I wrote a trace listener and every trace.WriteLine("xxxxx") adds the trace text as a row to a DataGridView control on my form. While my program cranks out a 300,000+ rows of mock data, and adds each row's worth of log text to the DataGridView control, the control kinda freezes up, the whole form really. Is there a way to make it more responsive / refresh more often?

Thanks!

Background: Not to say it was the best pick, but I used a DataGridView on the form because with a multiline textbox I thought appending each Trace.WriteLine() would have worse performance(string concatenations). And I couldn't see a way to work a StringBuilder object into the mix to overcome the concatenations issue, plus with StringBuilder I was worried the string length might exceed Integer.MaxValue of the SB object. I'm open to any other patterns that get me towards having basically a big text scrollable logfile in the middle of my vb app.
 
Mock or not, you shouldn't be putting that amount of data in UI, not in any type of control.
 
You could load your data in a dataset on a background thread (background worker) and then when done bind it to the grid and refresh. You may also want to use a higher performance grid such as the Developer Express XtraGrid.
 
I realise this thread is old but I'm curious about something...

@JohnH: Arguably it's never really a good idea to put too much info in the UI but what about instances when the purpose of an application IS to display that much info? Lately I've had to create a number of reporting apps (little ones) where it's been necessary for me to do exactly that. In a case like that are there any alternatives you can recommend or...?

Also, aside from using a DataGridView or a multiline TextBox why not use a ListBox? I have never really used a listbox for that much info but I would think it should be fast enough?

I know when I need to display logs in real time I normally just use a RichTextBox (please don't hurt me!) which I limit to a certain number of characters and whenever that number is exceeded I remove the oldest lines from it and display only the latest. Doing that with 300 000 lines would fail miserably though. From past experience string operations with a LOT of text takes a VERY VERY VERY VERY LONG time and destroys an application.
 
As JohnH mentions above putting that much data for display is usually a bad decision for several reasons and most of the time there is a better alternative. But to answer your question Ronin, most depends on what you need the data for and whether you need to manipulate it in the front end or not.

Storing larges amounts of data in a dataset takes up a lot of memory. However if the purpose of it is only for display purposes I would consider the datareader. Most other objects will fully process and retrieve all the data before updating the UI (which gives that freezing appearance). Where as a datareader takes just as long it will start displaying the data as it comes in.
 
When you need to display lots of data usually paging come into play, and/or master-details, and filters/search facilities. In some cases one could also analyze what needs to display (what user needs to find in all that data) and perhaps find ways to aggregate data display. DataGridView also has a virtual mode that allows for minimizing data kept in memory and UI.
 
Back
Top