2

What I have tried, The below line of code changes a complete column background color.

dataGridView.Columns[1].DefaultCellStyle.BackColor = Color.Yellow;

But, I want to work the same for only a selected row. For example, I have 4 columns in datagridview, and when I select the row. Selected rows should have a different background color for every column.

This is how am getting a selected row.

foreach (DataGridViewRow dvr in dataGridView.SelectedRows)
                {
                   dvr.Cells[0].Value.ToString();
                  
                }

I am able to get the cell value of the selected row but I can't access the cell value back color property.

Any idea how I can do this. Please help

Jimi
  • 29,621
  • 8
  • 43
  • 61
  • 1
    Okay i have got my question's solution and that is dvr.Cells[1].Style.BackColor = Color.Yellow; from Olivier Rogier's link https://stackoverflow.com/questions/16105718/ Thank you all for your guides . How do i accept your solution now? – Aaric Aaiden Aug 26 '21 at 10:02
  • Does this answer your question? [DataGridView changing cell background color](https://stackoverflow.com/questions/16105718/datagridview-changing-cell-background-color) –  Aug 26 '21 at 10:09

0 Answers0