Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2710
  • Last Modified:

VB.net Can't resize DataGridView rows or columns

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
Murray Brown
Asked:
Murray Brown
1 Solution
 
sammySeltzerCommented:
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
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now