如题

解决方案 »

  1.   

     StringBuilder str = new StringBuilder();
                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    //dataGridView1.Rows[i].Cells[0].GetType().ToString().Equals("System.Windows.Forms.DataGridViewCheckBoxCell")
                    if (dataGridView1.Rows[i].Cells[0].Value!=null)
                    {
                        str.Append(this.dataGridView1["columnIndex", i].Value.ToString());
                    }
                }
    不知道对你是不是有用
      

  2.   

    在VB.net区看到过类似的问题,给个链接吧http://topic.csdn.net/u/20100113/11/f4e5276e-fbec-4ff9-9a09-3ef6ba67f607.html?97674
      

  3.   


                if (this.dataGridView1.Rows[0].Cells[0].Value!=null)
                {
                    MessageBox.Show("true");
                }
                else
                {
                    MessageBox.Show("false");
                }
      

  4.   

    循环判断 为true就弄到一个集合里
      

  5.   

    楼上的,把true弄到一个集合里面 ,那如何写sql语句啊?
    判断我会,就是SQL语句写不出来,写出来的话也是只能得到一个而已
      

  6.   

    循环 checkbox 状态
    生成集合
      

  7.   

    SQL后面的条件如何写呢?
    selall="select * from tb where"条件"这里怎么写?才能得到所有选中的那些项???
      

  8.   

    select * from tb where id in { '1','2','3'}  ...对应checkbox行的id值
      

  9.   

    即,现在有两个form,一个form1,一个form2
    里面各有一个datagridview
    我在form1中的datagridview有一列是checkbox列,
    现在我要把如果checkbox为选中,那么按下添加,他就把这些选中的
    项添加到form2中的datagridview里如何实现
      

  10.   

    给一种思路,定义一个跟表结构相同的类,然后把form1中读出的数据以这个类对象的形式加入到集合或数组中,然后到form2中读取显示该集合。这种方式不用再次连接数据库进行查询。
      

  11.   

     foreach (DataGridViewRow row in this.dataGridView.Rows)
                {                    if(row.Cells["checkBox"].Selected )
                        {
                             //选中了
                        }
                }
      

  12.   

    实例一个datatable,遍历dgv1,如果checked,把数据取出存到datatable,遍历结束之后绑到dgv2
      

  13.   

    怎么循环我知道,就是不知道怎么把循环出来的数据一个一个的加到那个datatable中?我现在循环出来的都只是最后那一条,
    如果是删除选中的,那最快了,循环选中的,然后循环到选中的就删除,有几个就删除几次
    可是现在是添加,总不能是循环选择到的,有几个就添加几次吧就是如何把数据一个一个的加到数据表里面呢
      

  14.   

            private void Form1_Load(object sender, EventArgs e)
            {
                dataGridView1.AllowUserToAddRows = false;
                dataGridView2.AllowUserToAddRows = false;
                dataGridView1.Columns[1].DataPropertyName = "c1";
                dataGridView1.Columns[2].DataPropertyName = "c2";            DataTable dt = new DataTable();
                dt.Columns.Add("c1"); 
                dt.Columns.Add("c2");            DataRow dr;//行 
                for (int i = 0; i < 5; i++)
                {
                    dr = dt.NewRow();
                    dr["c1"] = i;
                    dr["c2"] = "Name" + i;
                    dt.Rows.Add(dr);//在表的对象的行里添加此行 
                }
                dataGridView1.DataSource = dt;
            }        private void button1_Click(object sender, EventArgs e)
            {
                DataTable dt = new DataTable();  //建立一个准备存储数据的新dt
                dt.Columns.Add("c1");
                dt.Columns.Add("c2");
                foreach (DataGridViewRow dr in dataGridView1.Rows)   //遍历dgv1
                {
                    DataRow r = dt.NewRow();
                    if (dr.Cells[0].Value != null && (bool)dr.Cells[0].Value == true)  //如果checked,开始复制数据
                    {
                        for (int i = 1; i <= 2; i++)
                        {
                            r[i-1] = dr.Cells[i].Value;
                        }
                        dt.Rows.Add(r);
                    }
                    
                }
                dataGridView2.DataSource = dt;
            }代码有点繁琐,你可以优化一下代码
      

  15.   

    Form1_Load里的东西你可以不看,没用
      

  16.   

    System.Text.StringBuilder cond = new System.Text.StringBuilder();
    foreach (DataGridViewRow row in this.dataGridView.Rows)
                {                    if(row.Cells["checkBox"].Selected )
                        {
                            //选中了
                               cond.Append(row.Cells[1].Value).Append(",");//如果是字符串要加''的
                        }
                }
    //selall= "select * from tb where 字段 in ("+cond.ToString().SubString(0,cond.ToString().Length-1))+")"
      

  17.   


    Selected不等于Checked,复制数据的话就不用再次连接数据库查询了