hello all

I fill datagridview Row[0].Cells[0] with the following command


how to give color so that the content "-1" in datagridview has red in color (forecolor)

thank you


You can use the CellFormatting event to do this.
The following code snippet colours cells in the third column if they have a value of "-1".

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
            var cell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
            if (e.ColumnIndex == 2 && ((string)cell.Value) == "-1")
                e.CellStyle.ForeColor =  Color.Red;

You must check the column index to ensure the test is applied to the right data value.