?
Solved

Autosizing a Form based on DataGridView size?

Posted on 2014-01-28
1
Medium Priority
?
714 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
[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
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

Independent Software Vendors: 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

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…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

777 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