Click here to Skip to main content
15,900,907 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I need to access a win forms datagridview's
dock properties from another
form. Hoiw is this possible?

Please any help would be appriciated.
Posted
Updated 6-Mar-12 23:34pm
v3
Comments
Shahin Khorshidnia 7-Mar-12 5:33am    
Firstly, please tag WinForm to your question. (If you mean WinForm DataGrid).
Secondly, Please specify the parent form and the child one. Or maybe both forms are children of another?
BobJanova 7-Mar-12 7:04am    
You almost certainly don't need to, and shouldn't, do this. A single form should generally be a self contained UI entity and you oughtn't to be poking about inside one from another. There are exceptions but they are unusual. Please say why you think you need to do this because there may well be a better solution to the actual problem you have.

1 solution

In your form make property which will expose particular grid or property to other objects.

For instance in your form with dataGridView you'll have:

C#
public DataGridView MyDataGridView
{
    get
    {
       return this.myDataGridView;
    }
}

public DockStyle MyGridsDockProperty
{
    get
    {
       return this.myDataGridView.Dock;
    }
    set
    {
       this.myDataGridView.Dock = value;
    }
}

//etc.

Other form will use that:
C#
public partial class MyOtherForm:Form
{
    private MyFormWithGrid _myFormWithGrid = null;

    ///CTOR
    public MyOtherForm(MyFormWithGrid myFormWithGrid)
    {
        InitializeComponnent();
        _myFormWithGrid = myFormWithGrid;
    }

    private void MyMethodToDealWithAnoterFormsProperties()
    {
        myFormWithGrid.MyGridsDockProperty = DockStyle.None;
    }

    //etc.
}

This is pretty straightforward Windows Forms basics, try using some of great tutorials or books available on internet.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900