Solved

VB.net Can't resize DataGridView rows or columns

Posted on 2014-02-13
2
2,549 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
ID: 39856087
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
ID: 39864627
Thanks very much
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
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…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

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