我在from1中定义了变量rows
并且通过操作给rows赋了值
那我如何在from2中得到这个变量rows的值???在线等,哪为大哥知道啊?

解决方案 »

  1.   

    定义成静态的就可以了,static,或者你将这个变量作为form2的构造函数的参数
      

  2.   

    ref:
    http://blog.csdn.net/knight94/archive/2006/03/18/628285.aspx
      

  3.   

    把你的这个rows定义成public static就可以了
      

  4.   

    大哥哥我是新手,可以给个例子吗?
    这里的rows是表里的ID
    rows=myDataGrid[myDataGrid.CurrentRowIndex,0];//将DataGrid中当前点击行的ID给rows
    我想要在from2中得到这个ID
    怎么做啊???
      

  5.   

    To use static is not a correct way here
      

  6.   

    ref:
    http://blog.csdn.net/zhzuo/archive/2004/04/05/22027.aspx
      

  7.   

    你的文章我看了,不过你是怎么用this的把第2个窗体弄出来的啊
    我是在工程里添加的from2
    from2 myfrom2 = new from2 () ;
    myfrom2.show();
    我是这样show的
    然后在from2中我重载了from2写了个构造函数,用 this.变量 的方法,但是报错啊
      

  8.   

    方法很多,试试用类的方法,在页面中添加类 //元素设置为静态
    public class xxx
    {
    private static int x;
    private static string y;
    private static bool z;
                     ……………………………………
    public static int x
    {
    get{return _x;}
    set{_x= value;}
    }
           public static string y
    {
    get{_y;}
    set{_y= value;}
    }
    public static bool z
    {
    get{return _z;}
    set{_z= value;}
    }
                     ……………………………………………………
    }
    其他窗体调用
    xxx.x =1;
    m = xxx.x;