zoukankan      html  css  js  c++  java
  • 20161020001 DataGridView 选中的 DataGridViewCheckBoxCell 不添加重复项

    private void btn_add_Click(object sender, EventArgs e)
            {
                string str_P_ID = "";
                string str_P_Type = "";
                string str_P_Name = "";

                int count = Convert.ToInt32(Dgv_Search.Rows.Count.ToString());
                for (int i = 0; i < count; i++)
                {
                    //如果DataGridView是可编辑的,将数据提交,否则处于编辑状态的行无法取到
                    Dgv_Search.EndEdit();

                    DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)Dgv_Search.Rows[i].Cells["ckb_check"];
                    Boolean flag = Convert.ToBoolean(checkCell.Value);
                    if (flag == true)     //查找被选择的数据行
                    {
                        //从 DATAGRIDVIEW 中获取数据项
                        str_P_Type = Dgv_Search.Rows[i].Cells["类型"].Value.ToString().Trim();
                        str_P_ID = Dgv_Search.Rows[i].Cells["ID"].Value.ToString().Trim();
                        str_P_Name = Dgv_Search.Rows[i].Cells["名称"].Value.ToString().Trim();

                        string str_Same = "0";
                        for (int i2 = 0; i2 < DataSet_tb.Tables[0].Rows.Count; i2++)
                        {
                            if (str_P_ID == DataSet_tb.Tables[0].Rows[i2]["ID"].ToString())
                            {
                                str_Same = "1";
                                continue;
                            }
                        }

                        if (str_Same != "1")
                        {
                            DataRow row = DataSet_tb.Tables[0].NewRow();
                            row["类型"] = str_P_Type.ToString();
                            row["ID"] = str_P_ID.ToString();
                            row["名称"] = str_P_Name.ToString();
                            DataSet_tb.Tables[0].Rows.Add(row);
                        }
                    }
                }

                Dgv_Confirm.DataSource = DataSet_tb.Tables[0];
                Dgv_Confirm_Init();

            }

  • 相关阅读:
    Javascript面向对象编程(二):构造函数的继承
    JS的封装(JS插件的封装)
    [Redis]Node操作Redis
    Linux中SSH客户端断开后保持进程继续运行配置方法的具体介绍
    linux防火墙查看状态firewall、iptable
    在Linux系统安装Nodejs 最简单步骤
    centos7 安装nodejs 最新版
    如何在Webstorm/Phpstorm中设置连接FTP,并快速进行文件比较,上传下载,同步等操作
    css实现图片横向排列,溢出隐藏/滚动条横向拖动
    设计模式——单例模式
  • 原文地址:https://www.cnblogs.com/hutie1980/p/5980288.html
Copyright © 2011-2022 走看看