我有一个datagridview,我希望将readonly
设置为true
两列。我想更改这些列的颜色。每当我离开细胞时,我只能使第一个细胞和当前细胞改变颜色。剩余的细胞不起作用。任何人都能帮助我吗?
答案 0 :(得分:3)
试
private void dataGridView2_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == 0)
if (dataGridView2[e.ColumnIndex, e.RowIndex].ReadOnly)
e.CellStyle.BackColor = Color.Red;
if (e.ColumnIndex == 1)
if (dataGridView2[e.ColumnIndex, e.RowIndex].ReadOnly)
e.CellStyle.BackColor = Color.Black;
}
答案 1 :(得分:2)
DataGridViewColumn dgv7col = dgv7.Columns[i];
DataGridViewCell cell = new DataGridViewTextBoxCell();
cell.Style.BackColor = Color.Wheat;
dgv7col.CellTemplate = cell;
你必须定义列而不是单元格Ronny
答案 2 :(得分:0)
简单:
if(grdView.Columns [" Columnname"] .ReadOnly) grdView.Columns [" Columnname"]。DefaultCellStyle.BackColor = Color.Lavender;
答案 3 :(得分:0)
foreach (DataGridViewColumn col in dgv.Columns)
if (col.ReadOnly)
col.DefaultCellStyle.BackColor = Color.Lavender;