两个窗体,frmContractRemind和frmContractRenewal。第一个窗体中放了一个DataGridView控件, 第二个窗体放了一个ListBox控件。现在我想把从DataGridView中获取的值,传到第二个窗体中的ListBox控件中,而且要考虑如果第一个窗体中的DataGridView中的DataGridViewCheckBoxColumn全选的话,也要全部传到第二个窗体中的ListBox去。请各位大鸟帮帮忙,最好能能写个例子。 

解决方案 »

  1.   

    点击窗体A中的某个控件,弹出了窗体BA中的数据传到B中那么在B窗体被创建的时候,将A中的值赋给在B中定义的属性在B中通过属性访问例如            ImportStockInfo isi = new ImportStockInfo();
                isi.bw = bw;
                isi.dwea = e;
      

  2.   

    1、获取“姓名”列的所有数据:            int iNameColumnNum=2;//姓名在第几列
                int iCount = this.dataGridView1.Rows.Count;
                string[] sName=new string[1000];
                if (iCount != 0)
                {
                    for (int i = 0; i < iCount; i++)
                    {
                        sName[i]=this.dataGridView1[iNameColumnNum, i].Value;
                    }
                }
    2、窗体间传值:            //姓名列所有数据
                public string[] sName=new string[1000];
                public string[] SName
                { 
                   get { return SName; }
                   set { SName = value; }
                }            //打开第二个窗体
                Form2 form2 = new Form2();
                form2.Owner = this;
                form2.Show();            //第二个窗体Form1_Load事件中
                  string[] sName2=new string[1000];
                  Form1 fForm = (Form1)this.Owner;
                sName2 = fForm.SName;
      

  3.   

    两个窗体,frmContractRemind和frmContractRenewal。第一个窗体中放了一个DataGridView控件, 第二个窗体放了一个ListBox控件。现在我想把从DataGridView中获取的值,传到第二个窗体中的ListBox控件中,而且要考虑如果第一个窗体中的DataGridView中的DataGridViewCheckBoxColumn全选的话,也要全部传到第二个窗……
    1、添加“toolStripButton”按钮,则做此按钮的单击事件:        private void toolStripButton_Click(object sender, EventArgs e)
            {
                int iCount = this.dataGridView1.Rows.Count;
                if (iCount != 0)
                {
                    for (int i = 0; i < iCount; i++)
                    {
                        b[i] = true;//哪些行的姓名需要在第二个窗体显示的标记,通过窗体传递
                        this.dataGridView1[0, i].Value = true;
                    }                this.pictureBox1.Refresh();
                }
                
            } 2、通过挨个勾选,产生事件:private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
            {
                if ((e.RowIndex >= 0) && (e.ColumnIndex >= 0))//列表为空时不响应
                {
                    DataGridViewColumn column = this.dataGridView1.Columns[e.ColumnIndex];
                    int currentRowIndex = this.dataGridView1.CurrentRow.Index;//选中的当前行                //所有CheckBox列
                    if (column is DataGridViewCheckBoxColumn)
                    {                    if (e.RowIndex == currentRowIndex && e.ColumnIndex == 0)//选中行、第0列
                        {                        DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)this.dataGridView1.Rows[currentRowIndex].Cells["Column1"];                        Boolean flag = Convert.ToBoolean(checkCell.Value);
                            if (flag == true)     //CheckBox被选中
                            {
                                //勾选事件                        
                          }
                            else
                            {
                                //未勾选事件                        
                            }                    }
                    }
                }
            } 
      

  4.   

    public static class test
    {
        public static string value;
    }
    第一个窗体:
    test.value=datagridview.Rows[i].Tostring();
    窗体二:
    ListBox.Item.Add(Test.value);
      

  5.   

    第一个窗口:
    frmContractRemind f1=new frmContractRemind ();
    f1.ShowLb=list;
    f1.Show();第二个窗口添加 这个属性public List<string> ShowLb
            {
                get
                {
                    return list;
                }
                set
                {
                    list = value;                for (int n = 0; n < list.Count; n++)
                        listBox1.Items.Add(list[n]);
                }
            }
            private List<string> list=null;
      

  6.   

    你所说的两个窗体是都打开着的,还是有一个是需要点击按钮弹出来。如果是后者就简单很多,你可以直接从构造方法将值传递过去。如果是前者,可以在触发事件里遍历Application.OpenForms找到你想要的赋值的窗体,找到后直接对控件赋值