Force resize of DataGridView columns
I had the same issue until I set the autosize mode:
dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
Additionally, I believe the object needs to be VISIBLE before the resize is done... for some reason, the painting doesn't appear to happen as one would expect.
You need to use AutoResizeColumns()
after your DataGridView
has data in it. That is the reason. Make sure SomeClass.Table
get the data before you call AutoResizeColumns()