问题
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