Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using this line of code to show content in gridview's cell
C#
dgvhadiths.Columns[3].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;

THIS WILL SHOW FULL DATA CONTENT IN CELL BUT THE PROBLEM IS; IT HAVE INCREASED MY GRIDVIEW WIDTH TOO MUCH.
I WANT to fit gridview width according to the size of my winForm plus i want to show complete content of cell of gridview (without the increasing of gridview width).
Posted

1 solution

You can set the width of the gridview, and even the column widths themselves. I would assume you want to wrap the text in the gridviw.

DefaultCellStyle.WrapMode = DataGridViewTriState.True
AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells

Note, if your data has no spaces in it, it may not wrap. if that is the case, you may need to write a method to insert line breaks every 10-15 amount of characters, depending on the size of your column.
 
Share this answer
 
Comments
Muhamad Faizan Khan 24-Dec-13 13:06pm    
my data has spaces now what to do?

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