Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB.net Can't resize DataGridView rows or columns

Posted on 2014-02-13
2
Medium Priority
?
2,677 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:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 29

Accepted Solution

by:
sammySeltzer earned 2000 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:Murray Brown
ID: 39864627
Thanks very much
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

705 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