C# Conditional formatting of DataGridView cells

  • Thread starter Thread starter JC Carmo
  • Start date Start date
J

JC Carmo

Guest
Hello everyone,

Greetings from Brazil! I have a DataGridView with a column named "Valor" that displays a currency amount in Brazilian Real (R$ and -R$). I am trying to make the cell ForeColor Red if the amount is negative, and Blue if the amount is positive. Ive tried the code below, but its not working. What am I doing wrong? Please help! I appreciate your time and expertise. Thank you!


private void tbl_caixaDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
for (int i = 0; i < tbl_caixaDataGridView.Rows.Count; i++)
{
if (Convert.ToInt32(tbl_caixaDataGridView.Rows.Cells["Valor"].Value) < 0)
{
tbl_caixaDataGridView.Rows.Cells["Valor"].Style.ForeColor = Color.Red;
}
}
}


Best regards,

JC Carmo :)



jcrcarmo

Continue reading...
 
Back
Top