views:

432

answers:

2

I have a form that contains dataGridView, whose coloumn are set to

dgrv1.Width =dgrv1.Columns.GetColumnsWidth(DataGridViewElementStates.Visible)+20;

I want to make the form to automaticaly follow the width of dataGridView...

Also, on maximized, I would like it to grow in height only.

Any sugestions?

A: 

Have you tried using the main form's OnChange event?

    private void MainForm_SizeChanged(object sender, EventArgs e)
    {
        this.Width = ...;
        this.Height = ...;
    }
m_oLogin
Do you mean:private void MainForm_SizeChanged(object sender, EventArgs e) { this.Width = ...; this.Height = ...; }?????
you're right my bad :)
m_oLogin
A: 

Well, you have got a Width value. Set both the MaximumSize and MinimuSize properties of the Form to that value. Maybe with a little margin in between.

Leave the Max/Min Height properties on 0 for default.

Additional:

this gives me a Form that can only be 200 width, but the default '0' for height seems not to work.

    private void Form1_Load(object sender, EventArgs e)
    {
        this.MinimumSize = new Size(200, 400);
        this.MaximumSize = new Size(200, 1200);

    }
Henk Holterman
"Set both the MaximumSize and MinimuSize properties of the Form to that value"----how do I do that???I've tried next: this.MaximumSize.Width = dgrv1.Width + 20;this.MinimumSize.Width = dgrv1.Width + 20; where "this" is a form... what is a problem there?
this works just great. Thank you