关于DataGridView中的c#:CheckBox值始终为true

天道酬勤!!! / 2023-07-25 / 原文

使用CellContentClick事件,然后使用EditedFormattedValue属性

 private void compGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0)
            {
                if ((bool)compGridView.Rows[e.RowIndex].Cells[0].EditedFormattedValue)
                {
                    ComputersList.Add(compGridView.Rows[e.RowIndex].Cells[1].Value.ToString());
                }
                else
                {
                    ComputersList.Remove(compGridView.Rows[e.RowIndex].Cells[1].Value.ToString());
                }
            }
        }