How to achieve multi line header in DataGridView using property grid?
Solution 1
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.
Solution 2
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;
Solution 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.
PJ2344
Updated on June 14, 2022Comments
-
PJ2344 almost 2 years
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? -
PJ2344 about 9 yearsThanks, though I am trying to do this in the property grid itself.. I don't find any way of doing that..
-
Cristina Alboni about 9 yearsYou mean in the aspx?
-
PJ2344 about 9 yearsNo, on the designer, when you try to add/edit columns, a window that pops up has the ability to take the header text values for the columns.. thats where I was trying to set the header text with multiple lines.