DataGridView bug with the AutoWrap and the AutoRowSize not resizing rows on scroll

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!

0 thoughts on “DataGridView bug with the AutoWrap and the AutoRowSize not resizing rows on scroll”

  1. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.