Reputation: 54
dgvSampled.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
I'm trying to size the columns with the AllCells
mode. The problem is that when the longest string in the column is the header, a buffer is left over.
Compare the Requested
column to the Coil #
column. Why does the Coil #
column size itself perfectly to its content, but the Requested
column sizes itself too large for its header title?
After making the columns unable to be sorted, they are now being sized as I expected them to be in the first place.
Upvotes: 2
Views: 638
Reputation: 15247
From the documentation (emphasis mine):
AllCells: The column widths adjust to fit the contents of all cells in the columns, including header cells.
From your description, it seems that what you want is DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader
Upvotes: 1