天天看点

C#DataGridView设置CheckBoxList

在DataGridview中点击添加一个CheckBoxList列

C#DataGridView设置CheckBoxList

添加完成后添加cellClick事件:

 if (e.RowIndex > -1 && dataGridView_Pipetype.SelectedCells.Count > 0)

                {

                    //点击button按钮事件“IsSelect”是我创建复选框列时候的列名

                    if (e.ColumnIndex != -1 && DataGridView_Config.Columns[e.ColumnIndex].Name == "IsSelect" && e.RowIndex >= 0)

                    {

                        bool Ischecked = Convert.ToBoolean(DataGridView_Config.Rows[e.RowIndex].Cells[e.ColumnIndex].Value);

                        DataGridView_Config.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = !Ischecked;

                    }

通过这个事件就可以进行更改复选框的状态。