2

2列に設定readonlyしたいdatagridviewがあります。trueそれらの列の色を変更したい。セルから離れるたびに、最初のセルと現在のセルの色のみを変更できます。残りの細胞は機能していません。誰でもこれで私を助けることができますか?

4

4 に答える 4

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;
}
于 2012-12-17T06:02:19.697 に答える
2
    DataGridViewColumn dgv7col = dgv7.Columns[i];
    DataGridViewCell cell = new DataGridViewTextBoxCell();
    cell.Style.BackColor = Color.Wheat;
    dgv7col.CellTemplate = cell;

セルRonnyではなく列を定義する必要があります

于 2014-06-24T10:13:37.040 に答える
0

単純:

if (grdView.Columns["列名"].ReadOnly) grdView.Columns["列名"].DefaultCellStyle.BackColor = Color.Lavender;

于 2016-07-01T11:12:40.687 に答える