Solved

VB.NET Resize datagrids as form grows and shrinks

Posted on 2015-01-30
5
161 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

717 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