I put my DataGridView on a Form and setup the autowrap on the cells. So far so good. Then I realized my rows didn’t autosize.
I set the dataGrid.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;.
That worked fine, until…..I had a few thousand rows. Then the grid’s performance sucked.
So, changed it to DisplayedCells. This worked awesome too, until I scrolled. So…….What to do? Well, time for the old workaround..
Simple code change, to correct their retarded flaw. Capture the Scroll event. Then throw this code in.
private void dataGrid_Scroll(object sender, ScrollEventArgs e)
{
//Workaround for datagrid view bug.
dataGrid.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedHeaders;
dataGrid.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCells;
}
That little gem of code will get you back on your way.
Happy Coding!
#1 by Alena on April 29, 2010 - 9:12 pm
This is great. I have been frustrated between 2 settings, resize based on all cells’ value, and only displayed cell. I’m glad to come across your post. This is great solution.
Thanks much.