Solved

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

Posted on 2014-03-08
3
2,802 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 62

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 62

Expert Comment

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

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

15 Experts available now in Live!

Get 1:1 Help Now