handyjay
asked on
How do I autosize my .NET windows form so my datagridview displays correct
I have a datagridview that I fill on page load in my VB.NET windows forms application. The cells in the datagrid are set to autosize allcells. I now want the windows form that holds the datagridview to autosize based on the size of the grid. I set the windows form autosize = true but it is not changing size.
What am I missing?
What am I missing?
Does setting the Dock property of the data grid to DockStyle.Fill have the desired result?
ASKER
no that does not work
Is the DataGridView the only thing on the form?
ASKER
yes
You can handle the Paint and Resize events of the DataGridView, and set the form to the same height/width of the DataGridView. e.g.,
Private Sub DataGridView1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles DataGridView1.Paint
Me.Size = Me.DataGridView1.Size
End Sub
Private Sub DataGridView1_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridView1.Resize
Me.Size = Me.DataGridView1.Size
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.