zoukankan      html  css  js  c++  java
  • 如何获取datagridview中checkbox选中的多行数据

    开发(winform)时碰到这个问题 C# 怎样判断 datagridview 中的checkbox列是否被选中,错误原因都C#对类型判断相当严格,为了避免大家以后多走弯路,把我的思路和大家说一下,希望对大家有帮助。

         for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    if ((bool)dataGridView1.Rows[i].Cells[0].EditedFormattedValue==true)
                    {
                        //TODO
                    }
                   
                }

    ===================================================================================

    private void PrintInFo() {
       try
         {
            int count = 0;
            //用于保存选中的checkbox数量
            //DG_List为datagridview控件
            for (int i = 0; i < DG_List.RowCount; i++)
            {
                if (DG_List.Rows[i].Cells  [0].EditedFormattedValue.ToString() == "True")
                //这里判断复选框是否选中
                {
                    count++;
                }
             }
             if (count == 0)
             {
                  MessageBox.Show("请至少选择一条数据!", "提示");
                  return;
             }
             else
             {
                  if (MessageBox.Show(this, "您要更新数据么?", "提示", MessageBoxButtons.YesNo,    MessageBoxIcon.Information).ToString() == "Yes")
                  {
                       for (int i = 0; i < count; i++)
                       {
                           ps.Pexcute(" update cf_prj_certi set FIsPrint='"+number+"' where fid='" +  DG_List.Rows[i].Cells["fnn"].Value.ToString() + "'"); //执行SQL
                       }
                   } else
                    {
                        return;
                    }
              }
         } catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            } this.ShowInfo(); //重新绑定datagridview
    }

    =========================================

    点击dataGridView1事件中的CellMouseClick 事件

    private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
    {
        if(e.ColumnIndex==6)
        {
            dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = true;
        }
    }

  • 相关阅读:
    使用 jfinal + beetl + bootstrap 实现商城展示及管理系统
    关于Node.js的__dirname,__filename,process.cwd(),./文件路径的一些坑
    canvas离屏、旋转效果实践——旋转的雪花
    走一步再走一步,揭开co的神秘面纱
    用javascript写一个emoji表情插件
    基于HTML5快速搭建TP-LINK电信拓扑设备面板
    百度地图获取规划路径信息
    devicePixelRatio 那些事儿
    怎样用JavaScript和HTML5 Canvas绘制图表
    首次写iPad布局感想(H5)
  • 原文地址:https://www.cnblogs.com/moss_tan_jun/p/2009996.html
Copyright © 2011-2022 走看看