views:

30

answers:

0

Or: How do I filter rows in a 'virtual mode' DataGridView?

What I try to do

I am writing a log viewer to display live program output. Since the application will run for a long time once started, I'll have to keep and display a huge number of log/data rows (several hundred thousands). The old implementation was a TextBox which was cleared after a fixed amount of rows. This was neither fast nor beautiful, so I decided to switch to a DataGridView based approach.

Currently I run the DataGridView in virtual mode. There is a thread constantly writing to the data list, which also keeps track of the maximum number of entries. After the data is added to the list it informs the DataGridView that the data has changed, so that I can keep the number of Invokes into the GUI thread small. The list itself is a BindingList<> which has RaiseListChangedEvents set to true; The implementation handles the events differently depending on where in the List data has been removed or added. (An optimization for the case that autoscrolling is disabled.)

Problem

Each row has an OutputLevel set, and only rows above a certain configured threshold should be displayed. If, however, the user decides to see all the verbose and debug output of the application, these rows should be displayed, too. Some sort of filter is needed.

My first approach was to subclass the DataGridView and Visible = false the affected rows in the OnRowPrePaint method. Unfortunately, I couldn't find a way to actually un-hide the hidden rows again afterwards. I read up a bit on the topic of hiding rows and found hints that I might use a DataTable and it's Filter options. As it turned out though, people asking about "how to turn a List<> into a DataTable" all basically got the same answer: Don't. (I'm not sure why though.)

Any ideas?