2012-10-02 123 views

回答

4

您可以使用CellFormatting事件:

private void dataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) 
{ 
    if (e.ColumnIndex == 1) 
     { 
      if ((int)e.Value == 3) 
       e.CellStyle.BackColor = Color.Blue; 
      if ((int)e.Value == 2) 
       e.CellStyle.BackColor = Color.Red; 
     } 
} 
1

你想这样

foreach (DataGridViewRow row in dataGridView1.Rows) 
{ 
    if (row.Cells[someColumnIndex].Value == 3) 
     row.Cells[someColumnIndex].Style.BackColor = System.Drawing.Color.Blue; 
    else if (row.Cells[someColumnIndex].Value == 2) 
     row.Cells[someColumnIndex].Style.BackColor = System.Drawing.Color.Red; 
} 

我希望这有助于一些事情。

相关问题