DataGridView AutoResizeColumns Method

Murray Brown
Murray Brown used Ask the Experts™
on
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
Comment
Watch Question

Do more with

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

Commented:
You can use the AutoSizeColumnsMode for that. For example, set it to AllCells.
Software Engineer
Commented:
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 BrownASP.net/VBA/VSTO Developer

Author

Commented:
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