Hi @OmkarHcl , Welcome to Microsoft Q&A.
Updated:
Just add the dataGridView1_CellFormatting event:
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Selected)
{
e.CellStyle.BackColor = Color.Red;
}
else
{
e.CellStyle.BackColor = dataGridView1.DefaultCellStyle.BackColor;
}
}
Note the RowsDefaultCellStyle.BackColor property.
You just need to use the code:
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.RowsDefaultCellStyle.BackColor = Color.Red;
}
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.