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

发布时间 2023-07-25 16:03:12作者: simadi

使用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());
                }
            }
        }