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

enter image description here

Solution 4

enter image description here

You can change open datagridview property directly

Share:
76,594
KeithDB
Author by

KeithDB

Updated on February 20, 2020

Comments

  • KeithDB
    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
    mannysz about 13 years
    This may not be enough. You should also set the row heights. Or dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
  • Chandan Kumar
    Chandan Kumar over 8 years
    Excellent Dude. You saved my time . Thumps up.