Changing datagridview cell color based on condition

前端 未结 12 1015
粉色の甜心
粉色の甜心 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 21:03

    private void dataMain_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (dataMain.Columns[e.ColumnIndex].Name == "colStatus")
            {
                if (int.Parse(e.Value.ToString()) == 2)
                {
                    dataMain.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.OrangeRed;
                    dataMain.Rows[e.RowIndex].DefaultCellStyle.ForeColor = Color.White;
    
                }
            }
        }
    

提交回复
热议问题