Changing datagridview cell color based on condition

前端 未结 12 1010
粉色の甜心
粉色の甜心 2020-12-02 20:36

I have loaded the data from database to datagridview and have two columns target value and volume where volume >target value that volume cell should be in green color and

12条回答
  •  天命终不由人
    2020-12-02 20:58

    foreach (DataGridViewRow row in dgvWebData.Rows)
    {
        if (Convert.ToString(row.Cells["IssuerName"].Value) != Convert.ToString(row.Cells["SearchTermUsed"].Value))
        {
            row.DefaultCellStyle.BackColor = Color.Yellow;
        }
        else
        {
            row.DefaultCellStyle.BackColor = Color.White;
        }
    }
    

    This Perfectly worked for me . even if a row is changed, same event takes care.

提交回复
热议问题