Click here to Skip to main content
15,885,878 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, I'm hoping find a simple solution to wrap text in a datagridview column. My text is too long and I have to scrol horizontally to read all of it. I'm hoping that by wrapping the text it will solve this issue. This is what I've tried but it hasn't worked for me.

VB
Public Property WrapMode As DataGridViewTriState
DataGridView1.Columns(0).DefaultCellStyle.WrapMode = DataGridViewTriState.True
Posted
Updated 20-Oct-16 23:27pm
Comments
TnTinMn 11-Oct-13 23:17pm    
I'm not sure why that did not appear to work for you. Have you set the AutoSizeRowsMode property?

DataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
CAS1224 12-Oct-13 9:14am    
This works, however it changes every column to wrap. If you post this as your answer I will gladly accept. Thanks so much
TnTinMn 12-Oct-13 10:15am    
What do you mean by "it changes every column to wrap""? All that property does is allow the row to set its height based on the tallest cell in the row. It does not change the style settings of any column. The default cell alignment is centered, if you prefer the other columns to show their content at the top of the cell, set their DefaultCellStyle.Alignment property to System.Windows.Forms.DataGridViewContentAlignment.TopCenter.

Per your request, I will post my comment as a solution so you can close out this thread.


CAS1224 12-Oct-13 10:23am    
"What I mean" is that I only want to wrap text on a single column, not the entire datagridview, but that's for me to figure out. Thanks again for the help.

I'm not sure why that did not appear to work for you.
Have you set the AutoSizeRowsMode property?

DataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
 
Share this answer
 
Comments
Niravvasoya 20-Jun-14 6:46am    
Thank you for Solution.... Excellent.....
Also set the

dataGridView.RowsDefaultCellStyle.WrapMode = DataGridViewTriState.True
 
Share this answer
 
Comments
CHill60 16-Oct-15 10:24am    
OP only wanted to wrap text on a single column (column 0), and already had the appropriate line of code in the question, which was posted 2 years ago.
Try this
DataGridView1.Columns(0).Styles.Add("word-wrap","break-word");
 
Share this answer
 
dataGridView.RowsDefaultCellStyle.WrapMode = DataGridViewTriState.True
dataGridView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900