C# very slow populating the datagridview

cdatagridview

I'am populating a datagridview from a datatable.

While populating the columns and rows, I also format it at the same time, this cause the datagridview to load very slowly, is there a work around for this problem?

Best Answer

As well as taking care of AutoSizeColumnsMode, make sure that individual columns have their AutoSizeMode property also set to something other than all cells.

I also found it necessary to use

SendMessage(dg.Handle, WM_SETREDRAW, false, 0); // before

// updates to datagridview here...

SendMessage(dg.Handle, WM_SETREDRAW, true, 0); // after