我在datagridview里面每次显示50条记录。我想像QQ邮箱里那样,每行前面有一个checkbox。可以选择我要的行。要怎么做呢。要拉50次checkbox吗。用checkedlistbox的话我拉动datagridview的滚动条,checklistbox不能跟着下。而且最后一页可能没有50条记录。该怎么做的呢?

解决方案 »

  1.   

    1 在设计页面选中GRIDVIEW控件,单击控件右上角的三角
    2 点击 编辑列 。
    3 添加一个 BoundField 将它调整至第1个
    4 点击 编辑列 窗口中,右下角的蓝色连接 “将此字段转换为”TemplateField
    5 确定退出。
    6 再次执行第1步,
    7 点击 编辑模板
    8 选中 你刚才添加的那个列(经过转换后)的 ItemTemplate
    9 将一个 Checkbox 拖到设计页面的ItemTemplate 中。OK 你看看效果。
    关于数据绑定的问题,你先把上面的弄通了,我再接着回复
      

  2.   

    Columns属性里加一个DataGridView CheckBox列...放按钮实现 全选/反选 功能啊......
      

  3.   

    用了3楼的方法。2楼说的是网页的吧。我做的是wingform。怎么确定有没有选中某一列呢。
      

  4.   

              用 Repeater 绑定数据 更加方便 
      

  5.   

    确定选择行....
    if(datagridview1.Rows[i].Cells["列名"].Value == null)
    {
       //没选中
    }
    else
    {
      if((bool)datagridview1.Rows[i].Cells["列名"].Value)
      {
        //选中
      }  
      else
      {
         //没选中
      }}
      

  6.   

          //全选/取消全选
         private void checkBox1_CheckedChanged(object sender, EventArgs e)
          {
            foreach (DataGridViewRow dr in this.datagridview1.Rows)
            {
             dr.Cells["列名"].Value = checkBox1.Checked;
            }
          }
          
          //反选
          private void checkBox2_CheckedChanged(object sender, EventArgs e)
          {
            foreach (DataGridViewRow dr in this.datagridview1.Rows)
            {
              if (dr.Cells["列名"].Value == null)
              {
                dr.Cells["列名"].Value = true;
              }
              else
              {
                dr.Cells["列名"].Value = !(bool)dr.Cells["列名"].Value;
              }
            }
          }
      

  7.   

    使用datagridviewcheckbox
    DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)dgv.Rows[i].Cells["check"];   
    checkCell.Value = false;
    dataGridView1.Rows[1].Cells[0].Value = true;
    foreach (DataGridViewRow dr in this.dataGridView1.Rows) {
    try {
    DataGridViewCheckBoxCell cbx = (DataGridViewCheckBoxCell)dr.Cells(0);
    if (Convert.ToBoolean(cbx.FormattedValue)) {
    str += dr.Cells(1).Value;
    }
    } catch (Exception ex) {
    MessageBox.Show(ex.Message);
    }
    }
      

  8.   

    又碰到问题了。我的原来的列名使用 datagridview.Columns[1].HeaderCell.Value = "日期";这样的代码加上去的,我在datagridview右边的三角里点添加的checkbox列显示不出来。好像被用代码加上去的列覆盖了。