How to resize datagridview control when form resizes

lowerkey picture lowerkey · Nov 18, 2011 · Viewed 130.3k times · Source

I found a lot of questions about how to resize the form when a child control resizes, but I'm trying to do something much simpler (maybe so simple people don't even ask it :| )

I'd like to automatically resize my datagridview's width to fill the width of the form. After simply placing the datagridview on the form, the grid stays the same size when the form is resized. That happens even when I use the little constant-distance-snap thing 'connecting' the control to the form's borders.

Do I have to handle a form.resize event of some sorts, or is there a property I can set in VS?

Answer

Samich picture Samich · Nov 18, 2011

Use control anchoring. Set property Anchor of your GridView to Top, Left, Right and it will resize with container. If your GridView are placed inside of some container (ex Panel) then Panel should be anchored too.