Solved

VB.NET Resize datagrids as form grows and shrinks

Posted on 2015-01-30
5
149 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks Mike, never used the tablelayoutPanel before but seems to do the trick.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

6 Experts available now in Live!

Get 1:1 Help Now