Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resize datagridview control when form resizes

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?

like image 818
lowerkey Avatar asked Nov 18 '11 13:11

lowerkey


People also ask

How to resize DataGridView?

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.

How to set size of DataGridView in c#?

To create fill-mode columns for values of varying size and importance. Set the DataGridView. AutoSizeColumnsMode property to Fill to set the sizing mode for all columns that do not override this value. Set the FillWeight properties of the columns to values that are proportional to their average content widths.

How set DataGridView size in VB net?

Set the property AutoSizeColumnsMode to be Fill . That'll ensure your columns stretch to 100% within your DataGridView. The columns will stretch/shrink when you resize your grid (if your grid is anchored to your form). Show activity on this post.

How to resize DataGridView columns in VB net?

Users can make size adjustments by dragging or double-clicking row, column, or header dividers. In column fill mode, column widths change when the control width changes; for example, when the control is docked to its parent form and the user resizes the form.


2 Answers

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.

like image 99
Samich Avatar answered Sep 17 '22 05:09

Samich


Set the property of your DataGridView:

Anchor: Top,Left AutoSizeColumn: Fill Dock: Fill 
like image 22
wreckseal Avatar answered Sep 18 '22 05:09

wreckseal