C# dataGricview 加选择框

  DataGridViewCheckBoxColumn columncb = new DataGridViewCheckBoxColumn();
            columncb.HeaderText = "选择";
            columncb.Width = 50;
            columncb.Name = "cb_check";
            columncb.TrueValue = true;
            columncb.FalseValue = false;
            //column9.DataPropertyName = "IsScienceNature";
            columncb.DataPropertyName = "IsChecked";
            grdData.Columns.Add(columncb);    

 

     

        private void SetAllRowChecked()
        {
            // DataGridCell cel=(sender as DataGridCell).
            int count = Convert.ToInt16(this.grdData.Rows.Count.ToString());
            for (int i = 0; i < count; i++)
            {
                DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)grdData.Rows[i].Cells["cb_check"];
                Boolean flag = Convert.ToBoolean(checkCell.Value);
                if (flag == false) //查找被选择的数据行
                {
                    checkCell.Value = true;
                }
            continue;
            }
        }

posted on 2016-08-29 19:03  澜貓  阅读(350)  评论(0编辑  收藏  举报

导航