How to achieve multi line header in DataGridView using property grid?

只愿长相守 提交于 2020-01-11 07:34:10

问题


I am trying to give the multi line header text in property grid for the DataGridView, I have used \n, \r\n but neither worked to get the header text in multiple lines. Is there a way other than setting the width of the column and leaving spaces to get this working using the property grid?


回答1:


If possible use Environment.NewLine (which is \r\n in Windows), and set the Grid column DefaultCellStyle.WrapMode property to DataGridViewTriState.True.

dataGridView.Columns[0].DefaultCellStyle.WrapMode = DataGridViewTriState.True;



回答2:


So I used Environment.NewLine in the designer.cs where the header text was assigned. Though the property grid shows just a string with no newline characters, while the GridView renders, the header text was coming in multiple lines as expected.




回答3:


The text ist taken literally, so in the Designer.cs File the HeaderText will be "First_Line\\r\\nSecond_Line". Just replace "\\" by "\" to "First_Line\r\nSecond_Line" and it works.



来源:https://stackoverflow.com/questions/29304406/how-to-achieve-multi-line-header-in-datagridview-using-property-grid

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