Changing datagridview cell color based on condition

前端 未结 12 1044
粉色の甜心
粉色の甜心 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:59

    private void dataGridView1_DataBindingComplete(object sender DataGridViewBindingCompleteEventArgs e)
    {
        foreach (DataGridViewRow row in dataGridView1.Rows)
        {
            if (Convert.ToInt32(row.Cells["balaceAmount"].Value) == 0)
            {
                row.DefaultCellStyle.BackColor = Color.Yellow;
            }
            else
            {
                row.DefaultCellStyle.BackColor = Color.White;
            }
        }
    }
    

提交回复
热议问题