Search code examples
c#winformsdatagridviewmultilinedatagridviewtextboxcell

How can I make the DataGridViewTextBoxColumn wrap to a new line if its text is too long?


My question is simple, but I can not think of an easy solution. Lets say I have a DataGridViewTextBoxColumn. How can I make it break text into several lines if it is too long to be shown in one line?


Solution

  • You need to create a new DataGridViewCellStyle class with the WrapMode property set to "True", and assign this to the DefaultCellStyle property of your DataGridViewTextBoxColumn.

    For example:

    DataGridViewCellStyle dgvCellStyle = new DataGridViewCellStyle();
    dgvCellStyle.WrapMode = DataGridViewTriState.True;
    
    myDataGridView.Columns[0].DefaultCellStyle = dgvCellStyle;