Coloring row in datagridview C #

0

I'm trying to use the following method:

  for (int i = 0; i < dgvRequisicao.Rows.Count; i++)
        {
            valor = Convert.ToDouble(dgvRequisicao.Rows[i].Cells["valor"].Value);

            if (valor > 20000.01 && valor < 100000)
                dgvRequisicao.Rows[i].DefaultCellStyle.BackColor = Color.Yellow;
            else if (valor > 100000.01)
                dgvRequisicao.Rows[i].DefaultCellStyle.BackColor = Color.Red;
        }

But you're not coloring at all.

Thank you

    
asked by anonymous 04.07.2016 / 19:48

1 answer

1

You will need to use the CellFormating event. .

private void dgvRequisicao_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
    valor = Convert.ToDouble((string)e.Value);

    if (valor > 20000.01 && valor < 100000)
        dgvRequisicao.Rows[i].DefaultCellStyle.BackColor = Color.Yellow;
    else if (valor > 100000.01)
        dgvRequisicao.Rows[i].DefaultCellStyle.BackColor = Color.Red;
}
    
04.07.2016 / 20:12