Winform:dataGridView中让某一单元格不可以编辑、修改背景颜色

单元格禁止编辑

 private void dataGridView_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
 {
          e.Cancel = true;
 }
private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
        {
            if(e == null)
            {
                return;
            }

            DataGridViewRow dgr = dataGridView1.Rows[e.RowIndex];
            if ((bool)dgr.Cells[columnUsed].Value)
            {
                dgr.Cells[columnFilterIndex].Style.BackColor = Color.Lavender;
            }
            else
            {
                dgr.Cells[columnFilterIndex].Style.BackColor = Color.White;
            }
        }

你可能感兴趣的:(c#,c#,winform,datagridview)