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

前端 未结 4 1478
滥情空心
滥情空心 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:19

    You can not directly set it to false. The correct way of setting it to false is:

    this.dataGridView1.ColumnHeadersDefaultCellStyle.WrapMode = DataGridViewTriState.False; 
    
    0 讨论(0)
  • 2021-02-18 18:21

    if you want to stop multiline text in DataGridView control then Wrap Mode should be false and set padding enter image description here

    0 讨论(0)
  • 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).

    0 讨论(0)
  • 2021-02-18 18:39

    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.

    0 讨论(0)
提交回复
热议问题