C#: multiline text in DataGridView control

前端 未结 7 802
[愿得一人]
[愿得一人] 2020-11-27 21:12

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

I am using Visual Studio 2005 and C#.

7条回答
  •  北海茫月
    2020-11-27 22:05

    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)

提交回复
热议问题