KeithDB
KeithDB

Reputation: 425

C#: multiline text in DataGridView control

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

I am using Visual Studio 2005 and C#.

Upvotes: 41

Views: 86552

Answers (7)

RameezAli
RameezAli

Reputation: 956

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

enter image description here

Upvotes: 8

bniwredyc
bniwredyc

Reputation: 8829

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)

Upvotes: 93

Sotheara
Sotheara

Reputation: 21

enter image description here

You can change open datagridview property directly

Upvotes: 2

ilker bayraktar
ilker bayraktar

Reputation: 1

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

Upvotes: 0

Rinky
Rinky

Reputation: 11

dgv.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
dgv.Columns[1].DefaultCellStyle.WrapMode = DataGridViewTriState.True;

Upvotes: 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;

Upvotes: 0

Roozi
Roozi

Reputation: 713

dgv.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
dgv.Columns[1].DefaultCellStyle.WrapMode = DataGridViewTriState.True;

Upvotes: 22

Related Questions