Solved

VB.net Can't resize DataGridView rows or columns

Posted on 2014-02-13
2
2,476 Views
Last Modified: 2014-02-17
Hi

I am trying to resize my DataGridView's columns and rows manually and using code like the following but they don't resize even though both AllowUserToResizeRows and AllowUserToResizeColumns are set to True
Me.DataGridView1.Rows(0).Height = 3000
0
Comment
Question by:murbro
2 Comments
 
LVL 28

Accepted Solution

by:
sammySeltzer earned 500 total points
Comment Utility
You may try a different approach by following the following steps to achieve your objective.

1.Go to the Design view
2.Click on the grid
3.Select "Edit Columns"
4.Add a column
5.The new column will be shown in the Edit Columns dialog, go to the Properties part of it and in the layout part of the properties, there's a height property. Set there the number of pixels that you want to have.

Same steps with existing columns

If for some reason that didn't help, although I think it will, then these code:

1) Place your Datagridview at the top-Left Corner i.e. at {0,0} position

2) Fill your Datagridview

3) Write the following code to resize the DatagridView---

'======================================================

  Me.DataGridView1.Width = 0

        Me.DataGridView1.Height = 0

        For Each column As DataGridViewColumn In Me.DataGridView1.Columns

            Me.DataGridView1.Width += column.Width

        Next

        Me.DataGridView1.Width += Me.DataGridView1.RowHeadersWidth

        For Each Rows As DataGridViewRow In Me.DataGridView1.Rows

            Me.DataGridView1.Height += Rows.Height

        Next

        Me.DataGridView1.Height += Me.DataGridView1.ColumnHeadersHeight

Open in new window


'=====================================================



Note: - (1) Form AutoSize=True

    (2) DataGridView ScrollBars=None


    (3) DataGridView Dock=None

Taken from the following link;

http://social.msdn.microsoft.com/Forums/windows/en-US/dc58f21c-654b-4db5-8b14-b44b3b570fb7/resize-datagridview-columns-on-form-resize?forum=winformsdatacontrols

Mundane difference I see is that no argument within ROW() function

Me.DataGridView1.Rows.Height = 3000 

Open in new window

0
 

Author Closing Comment

by:murbro
Comment Utility
Thanks very much
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
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.

772 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

11 Experts available now in Live!

Get 1:1 Help Now