How to set the DataGridViewCell to automatically word wrap?

just include the second line in code..... like in my code ... it is working perfectly

da.Fill(dtusers);

dataGridView1.DataSource = dtusers;
// dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
dataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True;

This may help someone.

If you need target specific columns use the below as what is int he question will not work, as items is not available in c# 4.5

dataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
dataGridView1.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
dataGridView1.Columns[2].DefaultCellStyle.WrapMode = DataGridViewTriState.True;

Just Add This Lines in form_Load Method

this.dataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True;

You also need to set DataGridView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells (along with what you have done) for word-wrap to work.

Tags:

C#

Winforms