欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

三、winForm-DataGridView操作——DataGridView 操作复选框checkbox

程序员文章站 2022-08-09 10:19:03
一、添加复选框 ArrayList arr = new ArrayList(); public string checkboxName = "选择"; void StandLibWin_Load(object sender, EventArgs e) { DataGridViewCheckBoxCo ......

 

  一、添加复选框 

三、winForm-DataGridView操作——DataGridView 操作复选框checkbox
    arraylist arr = new arraylist();
    public string checkboxname = "选择";
    void standlibwin_load(object sender, eventargs e)
        {
            datagridviewcheckboxcolumn checkcolunms = new datagridviewcheckboxcolumn();
            checkcolunms.name = checkboxname;
            checkcolunms.headertext = checkboxname;
            checkcolunms.width = 60;
            checkcolunms.truevalue = "1";
            checkcolunms.falsevalue = "0";
            datagridview1.columns.insert(1, checkcolunms);
            datagridview1.cellcontentclick += datagridview1_cellcontentclick;
          
        }
注册添加checkbox

  二、判断选中状态(此例添加一个arraylist用来存储选中行的标识)

三、winForm-DataGridView操作——DataGridView 操作复选框checkbox
        void datagridview1_cellcontentclick(object sender, datagridviewcelleventargs e)
        {
            if (e.rowindex > -1)
            {
                if (datagridview1.columns[e.columnindex].name == checkboxname)
                {
                    arr.clear();
                    for (int i = 0; i < this.datagridview1.rows.count; i++)
                    {
                        if ((bool)datagridview1.rows[i].cells[checkboxname].editedformattedvalue == true)
                        {
                            string vclickgridid = datagridview1.rows[i].cells["标识"].value.tostring();
                            arr.add(vclickgridid);
                        }
                    }

                }
            }
        }
遍历选中添加arraylist

  =================完结线==============================