Windows Develop Bookmark and Share   
 index > Windows Forms General > DataGridView - Automatically adjusting the width to match the column widths
 

DataGridView - Automatically adjusting the width to match the column widths

Is there a way to easily set the width of a DGV to be equal to total of the widths of all the columns?

I could set up a foreach loop to add up the widths, but was thinking there is probably a better way.
JimGuyer  Wednesday, September 09, 2009 7:39 PM
The potential problem there is that if you have many columns your form might not be big enough for the resized DGV.

One the other hand, if your grid is bigger than needed you can stretch the last column to fill. Look atAutoSizeColumnsMode.
Wole Ogunremi  Wednesday, September 09, 2009 8:07 PM

Select the data grid in the properties window set AutoSizeColumnsMode to Fill

Bharath kumar Y.S  Thursday, September 10, 2009 3:38 AM
The potential problem there is that if you have many columns your form might not be big enough for the resized DGV.

One the other hand, if your grid is bigger than needed you can stretch the last column to fill. Look atAutoSizeColumnsMode.
Wole Ogunremi  Wednesday, September 09, 2009 8:07 PM

Select the data grid in the properties window set AutoSizeColumnsMode to Fill

Bharath kumar Y.S  Thursday, September 10, 2009 3:38 AM
Excellent.

That worked prefectly

DataGridview1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill

Sorry for being slow to responf. I have been away.
JimGuyer  Monday, September 21, 2009 1:58 PM

You can use google to search for other answers

Custom Search

More Threads

• Raising a form or PropertyGrid in an user control
• Why would my Form a = new Form() be *CLONEING* itself? ie the new form != a
• create Graphic frequency Equalizer
• Create Email With Attachments Outlook 2003
• sharepoint services - search shared documents
• VB2005 Fill cells in Datagridview from other form
• Dynamic ToolStrip
• 3 keys pressed code?
• ToolstripControlHost and item reordering inside a Toolstrip
• .net 3.0 and limiting 1.1 written code to 1.1 framework only