Is it possible to prevent a multi line HeaderText in a DataGridView?

前端 未结 4 1479
滥情空心
滥情空心 2021-02-18 17:50

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

4条回答
  •  深忆病人
    2021-02-18 18:35

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

提交回复
热议问题