40

Is it possible for the DataGridView control to display multiline text in a cell?

I am using Visual Studio 2005 and C#.

informatik01
  • 16,038
  • 10
  • 74
  • 104
KeithDB
  • 415
  • 1
  • 4
  • 6
  • Some what similar post, please see http://stackoverflow.com/questions/1559867/how-to-set-datagridview-textbox-column-to-multi-line. – KMån Nov 10 '09 at 09:55

7 Answers7

88

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)

Massimiliano Kraus
  • 3,638
  • 5
  • 27
  • 47
bniwredyc
  • 8,649
  • 1
  • 39
  • 52
21
dgv.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
dgv.Columns[1].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
Roozi
  • 683
  • 6
  • 12
8

If you want to active the multiline text in DataGridView control then WrapMode should be true

enter image description here

daniele3004
  • 13,072
  • 12
  • 67
  • 75
RameezAli
  • 956
  • 11
  • 12
2

enter image description here

You can change open datagridview property directly

Pierre.Vriens
  • 2,117
  • 75
  • 29
  • 42
Sotheara
  • 21
  • 1
0

In my case, I got it to work this way (in addition to setting both AutoSizeRowsMode to AllCells and AutoSizeColumnsMode to AllCells):

dgvTwinReverb.Columns[PEANUT_GALLERY_COLUMN].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
dgvTwinReverb.Columns[PEANUT_GALLERY_COLUMN].MinimumWidth = PEANUT_GALLERY_COLUMN_DESIRED_WIDTH;
B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
0
dgv.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
dgv.Columns[1].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
Erwin
  • 4,757
  • 3
  • 31
  • 41
Rinky
  • 11
0
1- Datagridview > properties > DataGridViewCellStyle > WrapMode=True
2 -Datagridview > properties > DataGridViewCellStyle > AutoRowSizeMode=AllCells
3- Datagridview > properties > Cloumn >(cloumn selected which you want to multiline)
      DefaultCellStyle > Alingment=NotSet and WrapMode=NotSet