Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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#.

like image 655
KeithDB Avatar asked Nov 10 '09 08:11

KeithDB


1 Answers

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)

like image 108
bniwredyc Avatar answered Sep 19 '22 11:09

bniwredyc