C#: multiline text in DataGridView control

前端 未结 7 711
[愿得一人]
[愿得一人] 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 21:49

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

    0 讨论(0)
  • 2020-11-27 21:59
    dgv.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
    dgv.Columns[1].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
    
    0 讨论(0)
  • 2020-11-27 22:00

    You can change open datagridview property directly

    0 讨论(0)
  • 2020-11-27 22:01
    dgv.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
    dgv.Columns[1].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
    
    0 讨论(0)
  • 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)

    0 讨论(0)
  • 2020-11-27 22:09

    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;
    
    0 讨论(0)
提交回复
热议问题