Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
update textboxes with Streamreader 21 42
Syntax error 9 45
Put window Form inside tab page 10 26
I need help converting a bitmap to an image in VB.Net 1 14
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 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

14 Experts available now in Live!

Get 1:1 Help Now