Quick Fixes for SLOW DataGridView
After learning that you really don't want to try using the DataGridView in unbound mode (just get your data into a DataTable and let binding do the heavy lifting--binding doesn't suck anymore!), I had to next learn that the DataGridView can be really, really slow after you get more than a trivial amount of data in it.
For example, in a winforms app I'm working on, with a couple thousand rows in it, the grid would pause for up two seconds after the user clicked a checkbox in a cell. Ouch. The grid was also very slow to load, even using some tricks with SuspendLayout() and ResumeLayout().
Turns out all this slowness is due to painting issues, not data issues. Before you give up on the DataGridView as hopelessly slow, try these things:
* Set both AutoSizeColumnsMode and AutoSizeRowsMode to "None." If you want to call the AutoSizeColumns() method one time after you load the grid, that works pretty well, especially if you auto size based on the headers. You can also resize certain columns using the AutoSizeColumn() method or by setting a literal value for the Width propery.
* Set EnableHeadersVisualStyles to False. You will lose a little bit of "slickness" in your grid's appearance, but it will speed up considerably. It seems that enabling this feature makes the grid "inherit" its visual style from the OS style. Check the documentation or intellisense for a more specific description.
* I saw a suggestion on this page to turn off cell borders (CellBorderStyle = DataGridViewCellBorderStyle.None), but I did not try this one myself.
That same page linked above also confirms that the .NET 2.0 DataGridView is slower than the .NET 1.1 DataGrid. They must not have done a lot of testing with the autosizing and visual styles turned on. Hopefully a future release will improve things, but I shall not be holding my breath since I half suspect Microsoft is going to start letting winforms languish in favor of WPF...
This page also points to a DataGridView FAQ document that has some useful information.
Hope that helps,
Dan


Another tip to speed up DataGridView
In unbound (non-Virtual) mode it's much faster to add all the rows at the beginning and then fill the cells than it is to add the rows one at a time inside the filling loop.
e.g.
Rather than:
Use: