
We need to iterate through all the data in the grid and a DataTable supports enumeration. Cast out a DataTable from the target grid datasource. Public static void FastAutoSizeColumns(this DataGridView targetGrid)

/ Provides very fast and basic column sizing for large data sets. Set the AutoSizeColumnsMode to DataGridViewAutoSizeColumnsMode.None and call this method after setting the DataSource. I created this extension method for manually measuring and resizing columns in a DataGridView. I know I'm late to the party, but I recently got fed up with how slow the auto resizing was for the the DataGridView control, and felt someone somewhere might benefit from my solution. The link to the source article with the sample: If you do not need 2-way data-binding or some features provided by BindingSource (filtering, etc.), you may consider adding rows at one go with the () method. SendMessage(dataGridView1.Handle, WM_SETREDRAW, true, 0) SendMessage(dataGridView1.Handle, WM_SETREDRAW, false, 0) Private static extern int SendMessage(IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam)

PropertyInfo pi = dgvType.GetProperty("DoubleBuffered",īindingFlags.Instance | BindingFlags.NonPublic) ĭisabling the redrawing with the WinAPI WM_SETREDRAW message also helps: // *** API Declarations *** Check whether the DGV double buffering is turned on properly: if (!.TerminalServerSession)

Generally turning auto-sizing off and double buffering help to speed up DataGridView population.
