Solved

VB.net Can't resize DataGridView rows or columns

Posted on 2014-02-13
2
2,508 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

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
A short film showing how OnPage and Connectwise integration works.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

948 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

22 Experts available now in Live!

Get 1:1 Help Now