title: How can I set cell font colour in a DataGridView?
body: <p>I have a C# Winforms application where I need to set the cell font colour programmatically. If a condition is met, the font should be red. I have confirmed the condition check is correct, the problem is in the line</p>
  
  <pre><code> dgv_Table.Rows[cell.RowIndex].Cells[cell.ColumnIndex].Style.ForeColor = Color.Blue;
  </code></pre>
  
  <p>Where "cell" is the cell I'm currently checking. This does absolutely nothing. Even if I take it out of the loop and check like this:</p>
  
  <pre><code>dgv_Table.Rows[0].Cells[0].Style.ForeColor = Color.Blue;
  </code></pre>
  
  <p>It still does nothing. The lines of code are in a helper function called during Main().</p>
  
  <p>If I set DefaultCellValue, that does change the view, but is not what I want. </p>
  
  <pre><code> private void Main_Load(object sender, EventArgs e)
      {
          dgv_Table.Rows[0].Cells[0].Style.ForeColor = Color.Blue;
          dgv_Table.Rows[0].Cells[0].Style.BackColor = Color.Black;
          foreach (DataGridViewRow row in dgv_Table.Rows)
          {
              foreach (DataGridViewCell cell in row.Cells)
              {
                  cell.Style.BackColor = Color.Black;
                  if (cell.OwningColumn.Name == "RiskName" &amp;&amp; cell.Value.ToString() != "")
                  {
                      string wholeText = cell.Value.ToString();
                      int score = Convert.ToInt32(wholeText.Substring(wholeText.IndexOf("[") + 1, wholeText.IndexOf("–") - 1));
                      if (score &gt; 300)
                      {
                          dgv_Table.Rows[cell.RowIndex].Cells[cell.ColumnIndex].Style.ForeColor = Color.Blue;
                      }
                  }
              }
          }
  
      }
  </code></pre>