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 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).