Solved

Help with Auto sizing DataGridview's height using VB.NET

Posted on 2014-03-08
3
3,136 Views
Last Modified: 2014-03-08
Hi,

Is it possible to resize the height of a DataGridView depending on the number of rows to see all the rows in the Grid?

Thanks,

Victor
0
Comment
Question by:vcharles
  • 2
3 Comments
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 39915147
Hi Victor;

You can but you need to understand something. By default the rows in a grid are set to a size. This size can be changed by the programmer and therefore a grid with multiple rows can also have multiple row height. There can be no controls under the grid otherwise the grid will hide them. There may be more rows then can be displayed on the form.  Now that you understanding this you can do something like this:

' Get the number of rows in the grid and multiply it by the first row height. This assumes all rows are of the same height. You may want to add 1 more row to account for the header row.
DataGridView1.Height = DataGridView1.Rows.Count() * DataGridView1.Rows(0).Height

Open in new window

0
 

Author Comment

by:vcharles
ID: 39915167
Hi,

I understand your point, the grids are in a Tablelayoutpanel panel which rows are set to autosize and the control is set to autoscroll.

It worked.

Thank You.

Victor
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 39915170
Not a problem, glad it worked out for you.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET 2008 Winforms Signing 13 32
VB.net capture  result of a SQL query in variables 3 21
Syntax Issue with SSIS module 26 104
Need help Creating PowerShell Script 5 55
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
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 …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

828 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