Solved

VB.NET Resize datagrids as form grows and shrinks

Posted on 2015-01-30
5
157 Views
Last Modified: 2015-02-01
Hey guys, I'm pretty new to VB and have put together a form which has 3 datagrids, a few buttons and some labels.

Grid 1 contains 1 column and is located to the left of the screen, grid2 contains 5 columns and is in the middle, grid3 has 4 columns and located to the right.

I've anchored the grids as below:
Grid1: Top, bottom, left, right
Grid2: Top, bottom, right
Grid3: Top, bottom, right

When I shrink and grow the form from the top and bottom everything shrinks and grows accordingly, no problem.

When I shrink the form from the right or left, only grid1 shrinks and grows. If I drag the form in and start to shrink it, I can see grid1 is getting smaller while grid2 and grid3 remain the same size (see screenshot 1).

Not sure if this is expected or if I'm doing something wrong.

I guess what I'm trying to achieve is to have all the grids shrink, not just grid1.

I have tried anchoring grid2 to top, bottom, left and right, which then does shrink, but when the form is resized it leaves a large gap between grid1 and grid2 (see screenshot 2).


grid1-resizing-only.png
grid2-set-to-all-4-points.png
0
Comment
Question by:amaru96
  • 3
  • 2
5 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 40581136
You're probably looking for a TableLayoutPanel:
https://msdn.microsoft.com/en-us/library/system.windows.forms.tablelayoutpanel%28v=vs.110%29.aspx

How do you want them to resize, though?

Do you want them to all keep their relative size to each other?...but take up the whole width?

It's possible to make some of them fixed width and others take up a certain percentage, etc...

You have to be very specific in describing how they should resize if you want a good answer.
0
 
LVL 1

Author Comment

by:amaru96
ID: 40581171
Hi Mike, I'd like them to all resize evenly and maintain the same distance from one another.
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 40582131
You'd setup your TableLayoutPanel with 3 columns and 1 row:
TableLayoutPanel w/ 3 Columns
The percent sizes are relative to each other.  This means the third column would be 4 times as wide as the first column, and the second column would be 8 times as wide as the first column and 2 times as wide as the third.  The one row would just be any number with the percent type.

Now just add your grids to each column and set their Dock property to Fill.
0
 
LVL 1

Author Comment

by:amaru96
ID: 40582221
Thanks Mike, never used the tablelayoutPanel before but seems to do the trick.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 40582652
The TableLayoutPanel is extremely flexible once you learn how to use it.  You can make controls span columns and rows, and you can even nest TableLayoutPanels (or other containers) within each other to make very complex layouts.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question