Solved

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

Posted on 2014-03-08
3
3,035 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

831 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