Changing datagridview cell color based on condition

前端 未结 12 1043
粉色の甜心
粉色の甜心 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条回答
  •  猫巷女王i
    2020-12-02 20:54

    You need to do this

    private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
    {
        foreach (DataGridViewRow Myrow in dataGridView1.Rows) 
        {            //Here 2 cell is target value and 1 cell is Volume
            if (Convert.ToInt32(Myrow .Cells[2].Value)

    Meanwhile also take a look at Cell Formatting

提交回复
热议问题