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

x
?
Solved

Autosizing a Form based on DataGridView size?

Posted on 2014-01-28
1
Medium Priority
?
729 Views
Last Modified: 2014-01-29
I have a simple form that contains a Label, DataGridView and a Panel and within the Panel, a Label and ComboBox.

What I'm trying to do is autosize the form and not sure how to calculate the dimensions of the DGV. Here is my code.

    Private Sub CalculateControlPositions()
        Try
            lblItemInfo.Top = 0
            lblItemInfo.Left = 0
            lblItemInfo.Width = Me.Width
            lblItemInfo.Height = 28

            pnl.Top = lblItemInfo.Height + dgvSpecs.Height
            pnl.Left = 0

            dgvSpecs.Top = lblItemInfo.Height

            rowHght = dgvSpecs.RowCount * dgvSpecs.RowTemplate.Height

            Me.Size = New Size(dgvSpecs.Width + 26, rowHght + pnl.Height + 26)
            Me.ClientSize = New Size(dgvSpecs.Width, rowHght + pnl.Height)

            EH.ErrorMessage = ""

        Catch ex As Exception
            EH.ErrorMessage = "CalculateControlPositions() - " & ex.Message & "~E"
        End Try

        EH.ProcessMessages(frmMain, frmMain.sbr, EH.ErrorMessage)
    End Sub

Open in new window

0
Comment
Question by:BlakeMcKenna
1 Comment
 
LVL 14

Accepted Solution

by:
Matti earned 2000 total points
ID: 39817492
The event is a bit problem, you found some event from the grid or just use the code that updates it.

grid.left = 0
Me.height = Grid.height
Me.width = Grid.width

Of cause if you need to fit this perfect you need calculate all borders and bar sizes from API call's and use them to minus some of the grid size, you can estimate this, but it's not good in all operating system settings.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

926 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