DataGridView AutoResizeColumns Method

Murray Brown
Murray Brown used Ask the Experts™
Hi. Can I resize all the columns in one go or set them to resize to whatever data there is.
What code would I use? Does this happen after databinding
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Robert SchuttSoftware Engineer

You can use the AutoSizeColumnsMode for that. For example, set it to AllCells.
Software Engineer
A specific example:

Me.DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnMode.AllCells

Open in new window

But you can also set it at design time in the properties.
Murray Developer


Great answer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial