I have a DataGridView
which columns I want resized to the biggest cell from all that column's items, including the header. I have this:
dataGridViewMain.ColumnHeadersHeight = 60;
dataGridViewMain.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
Why does that code result in a few columns looking like this:
There is clearly more space reserved than necessary and I checked all the rows. None contain more than 3 characters. This behavior also happens on various columns. It looks like AutoResizeColumns
calculates the space required without taking into account that the column header has a size of 60 and can accommodate various rows of text.
Your grid header is re-sizing to the header text.
There is a property in dataGridViewMain
you need to adjust.
Set as follows;
dataGridViewMain.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
Also this can be set via Property Window;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With