C#: multiline text in DataGridView control
76,594
Solution 1
You should set DefaultCellStyle.WrapMode
property of column to DataGridViewTriState.True
. After that text in cells will be displayed correctly.
Example (DataGridView
with one column):
dataGridView1.Columns[0].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
dataGridView1.Rows.Add("test" + Environment.NewLine + "test");
(Environment.NewLine
= \r\n
in Windows)
Solution 2
dgv.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
dgv.Columns[1].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
Solution 3
If you want to active the multiline text in DataGridView
control then WrapMode
should be true
Author by
KeithDB
Updated on February 20, 2020Comments
-
KeithDB about 4 years
Is it possible for the DataGridView control to display multiline text in a cell?
I am using Visual Studio 2005 and C#.
-
mannysz about 13 yearsThis may not be enough. You should also set the row heights. Or dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
-
Chandan Kumar over 8 yearsExcellent Dude. You saved my time . Thumps up.