我在一个 datagridview查出一些数据通过DataGridViewCheckBoxColumn多选后按确定按钮 然后弹出另一个窗体把这些数据传到这个窗体的datagridview中并显示出来

解决方案 »

  1.   

    把第一个DATAGRIDVIEW设置成public的(属性),然后第二个页面就可以操作了,是父子关系吧············
      

  2.   


                //form1
                List<DataGridViewRow> dgvrows = new List<DataGridViewRow>();
                foreach (DataGridViewRow row in this.dataGridView1.Rows)
                {
                    //假设你第一列是CheckBox
                    if ((bool)row.Cells[0].Value)//选中
                    {
                        dgvrows.Add(row);
                    }
                }
               
                //form2
                this.dataGridView1.DataSource = dgvrows;
      

  3.   


    //Form1
          DataTable dt = new DataTable();
          dt.Columns.Add(new DataColumn("列1"));
          dt.Columns.Add(new DataColumn("列2"));
          for (int i = 0; i < dataGridView1.Rows.Count; i++)
          {
            if (dataGridView1.Rows[i].Cells["check列"].Value == null)
            {
              continue;
            }
            if ((bool)(dataGridView1.Rows[i].Cells["check列"].Value) == true)
            {
              DataRow dr = dt.NewRow();
              dt.Rows.Add(dr);
              dt.Rows[i]["列1"] = dataGridView1.Rows[i].Cells["你要存的列名1"].Value.ToString();
              dt.Rows[i]["列2"] = dataGridView1.Rows[i].Cells["你要存的列名2"].Value.ToString();
            }
          }
        }/*大概就是这样  你只需要把这个dt传到另外一个窗体中就可以了 */Form2 f2 = new Form2();
    f2.Dt = dt;
    f2.Show();/***************************************/
    //Form2://Form2中写一个公共属性 用于接收Form1的dtprivate DataTable dt;
    public Datatable Dt
    {
      get{return dt;}
      set{dt = value;}
    }Load事件中写
    datagridview1.DataSource = dt;
      

  4.   

              DataRow dr = dt.NewRow();
              dt.Rows.Add(dr);
              dt.Rows[i]["列1"] = dataGridView1.Rows[i].Cells["你要存的列名1"].Value.ToString();
              dt.Rows[i]["列2"] = dataGridView1.Rows[i].Cells["你要存的列名2"].Value.ToString();
     dt.Rows[i]["列1"] 这个里面的"列1"是索引吧 我checkbox 是0  然后从1开始是我要的值 可我运行老说找不到1