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

一笑奈何 提交于 2019-12-21 06:58:58

问题


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 header:

What I want:

+-----------------------+---
| Measurement Value (%) | ...
+-----------------------+---

What I get:

+-----------------------+---
| Measurement Value     | ...
|(%)                    |
+-----------------------+---

There is more than enough space to display all header cells without the lines breaks, but for whatever reason it is still inserted even when I set the AutoSizeMode to HeaderCell.

How can I prevent these line breaks, while still keeping the spaces in the HeaderText?


回答1:


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.




回答2:


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

this.dataGridView1.ColumnHeadersDefaultCellStyle.WrapMode = DataGridViewTriState.False; 



回答3:


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



来源:https://stackoverflow.com/questions/9507614/is-it-possible-to-prevent-a-multi-line-headertext-in-a-datagridview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!