我设了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了,为什么呀?
}

解决方案 »

  1.   

    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
    这是部分代码
      

  2.   

    //子窗体中
    public FrmMain myMain;//通过this.myMain来访问父窗体的相关对象//父窗体中(FrmMain)
    //创建子窗体
    FrmSubWin mySubWin=new FrmSubWin();
    mySubWin.myMain=this;//传进父窗体实例
    mySubWin.Show();注意,同时需要把父窗体中相关的对象进行public。
      

  3.   

    补充一下楼上的,最好不要更改控件的作用范围定义(如把private改成public)。你可以把你的控件用属性封装起来,子窗体通过相应属性来访问父窗体的控件。一个例子:
    对于private System.Windows.Forms.TextBox Homeaddresstxt;控件你可以
    public Button txtHOMEADDRESS
    {
       get
       {
          return this.Homeaddresstxt;
       }
    }
      

  4.   

    通过窗体属性Parent获取父窗体就可以对父窗体进行操作了,
    方法定义为public就可以了