Reputation: 1939
I have many Headers in the datagridview and the HeaderText is quite long for example 4 words. So the Datagridcell becomes big. I want to break the 4 words and put one by one below to reduce the size.
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcolumn.headertext.aspx
I tried checking the above link but I couldn't succeed.
Upvotes: 2
Views: 1659
Reputation: 9793
dataGridView.ColumnHeadersHeightSizeMode =
DataGridViewColumnHeadersHeightSizeMode.AutoSize;
foreach (DataGridViewColumn column in dataGridView.Columns)
{
column.HeaderCell.Style.WrapMode= DataGridViewTriState.True;
}
Upvotes: 1
Reputation: 1538
Try this:
dataGridView1.Columns[0].HeaderText = "VeryLong " + "LongLong" + Environment.NewLine + "LongLongLong";
Environment.NewLine
made line break
Upvotes: 1
Reputation: 16144
First Option: If you are looking for wrapping the text, the you can do that using CSS. Apply the class to your datagrid header.
Allow long words to be able to break and wrap onto the next line:
.wrapText {word-wrap:break-word;}
or
.wrapText {word-wrap:normal;}
normal - Break words only at allowed break points break-word - Allows unbreakable words to be broken
Second Option: You can use datagrid "HeaderStyle" tag:
<HeaderStyle Wrap="True" />
Upvotes: 0