When the length of the HeaderText
property reaches a certain character limit and there is a space in the text, WinForms automatically inserts a link break in the he
You can not directly set it to false. The correct way of setting it to false is:
this.dataGridView1.ColumnHeadersDefaultCellStyle.WrapMode = DataGridViewTriState.False;
if you want to stop multiline text in DataGridView control then Wrap Mode should be false and set padding
You could either set the ColumnHeadersDefaultCellStyle.WrapMode
to DataGridViewTriState.False
as the other answers already proposed
or
you could replace the spaces \s
in your header string with non-breakable spaces \u00A0
. The second solution has the benefit that you could set manual line breaks using \n
in your header string and avoid auto wrapping. E.g.:
+----------------------------------------------+
| A\u00A0very\u00A0long\u00A0first\u00A0Line\n |
| A\u00A0second\u00A0very\u00A0long\u00A0line |
+----------------------------------------------+
The first solution is not allowing manual line breaks (everything is one line).
The ColumnHeadersDefaultCellStyle
property of the DataGridView
has a boolean property called WrapMode
. This is true by default. Make it false to set the required behaviour.