Solved

VB.NET Resize datagrids as form grows and shrinks

Posted on 2015-01-30
5
153 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 85

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 85

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 85

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now