修改子窗体的构造函数(或添加一个构造函数),添加一个DataGrid参数,然后在父窗体中实例化子窗体的时候将DataGrid作为参数传递给子窗体。

解决方案 »

  1.   

    父窗体中的datagrid设为public;
    子窗体中:
    ((ParentForm)this.parent).datagrid1...
      

  2.   

    父窗体中的datagrid的什么值设为public?
    子窗体中是在private void Form2_Load函数中设吗?我是小菜鸟,谢谢答复
      

  3.   

    将DataGrid作为参数传递给子窗体。
      

  4.   

    父窗体中的datagrid的什么值设为public?
    子窗体中是在private void Form2_Load函数中设吗?我是小菜鸟,谢谢答复
    ==========================================================
    在设计视图中选datagrid,属性中的Modifiers属性从private改为public。
    或者在代码中改:类构造函数的上边的datagrid声明处,由private改为public。
      

  5.   

    SimonSnow(西门雪)假的把,家伙片我
      

  6.   

    不片你。子窗体中是在private void Form2_Load函数中设吗?我是小菜鸟,谢谢答复
    ==========================================================
    子窗体中要引用datagrid的地方用((ParentForm)this.parent).datagrid1
      

  7.   

    同意楼上,不过ParentFrom启动子窗体时要 ShowDialog( this )
      

  8.   

    好,我想在一个子窗口中访问所有父窗口中所有的对象,在父窗口中有DataGrid,DataSet,DataAdapter,DataConnection,点击父窗口的一个按钮,就实例化一个子窗口,在子窗口上做相关的查询,查询结果放入父窗口的DataGrid中,总而言之就是子窗口要能访问到父窗口的所有对象,并能改变其属性。
      

  9.   

    我设了Public但是就是不能访问,这是主窗口的按钮
    private void AdvSer_Click(object sender, System.EventArgs e)
    {
    if(StateSearchFrm==false)//判断是否有Search实例
    {
    Search f=new Search(this);
    f.Show();
    } }这是自窗口的查询按钮
    private void Seachbtn_Click(object sender, System.EventArgs e)
    {

    想在这里引用DataGrid,DataSet,DataAdapter,DataConnection再查询,就是不能引用请帮忙,在父窗口里面我已经设成Public了,为什么呀?
    }
      

  10.   

    public System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter;
    public Commitee.CMDataSet cmDataSet;
    private System.Windows.Forms.Label Posisionlbl;
    private System.Windows.Forms.Label Statelbl;
    private System.Windows.Forms.Label Clanlbl;
    private System.Windows.Forms.Label Schoolarshiplbl;
    private System.Windows.Forms.Label Workspacelbl;
    private System.Windows.Forms.Label Unitaddresslbl;
    private System.Windows.Forms.Label Unitphonelbl;
    private System.Windows.Forms.Label Unitcodelbl;
    private System.Windows.Forms.TextBox Statetxt;
    private System.Windows.Forms.TextBox Clantxt;
    private System.Windows.Forms.TextBox Schoolarshiptxt;
    private System.Windows.Forms.TextBox Workspacetxt;
    public System.Windows.Forms.TextBox Unitaddresstxt;
    private System.Windows.Forms.TextBox Unitphonetxt;
    private System.Windows.Forms.TextBox Unitpostcodetxt;
    private System.Windows.Forms.Label Memolbl;
    private System.Windows.Forms.TextBox Memotxt;
    private System.Windows.Forms.Label Grouplbl;
    private System.Windows.Forms.TextBox Grouptxt;
    private System.Windows.Forms.TextBox IsSCtxt;
    private System.Windows.Forms.Label IsSClbl;
    private System.Windows.Forms.TextBox Homeaddresstxt;
    private System.Windows.Forms.Label Homeadresslbl;
    private System.Windows.Forms.La
    这是部分代码