Reputation:
A DataGridView
column header may be set with code below, this quite set multiline header labels just fit and nice.
ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize
But a single line column header shapes quite ugly, namely a narrow row. Trying below code together to increase height even does not work:
Columns[0].HeaderCell.Style.Padding = new Padding(0, 5, 0, 5)
Is there way both use AutoSize
and get nice height of column header in case of single line labels?
Upvotes: 2
Views: 2000
Reputation:
if you set ColumnHeadersHeightSizeMode
to AutoSize
then it is not allowed to change Column Heigt
on run time in accordance with Header Labels Length
.
You must add this code on initialize:
this.dataGridView1.ColumnHeadersDefaultCellStyle.Padding = new System.Windows.Forms.Padding(0, 5, 0, 5);
Change '5' as you wish to what padding volume you would like see...
Upvotes: 2
Reputation: 2578
try this
dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
Upvotes: 0