Change the row color of the DataGridView

3

I would like to know how to change the color of a whole line of DataGridView . I have a code below, but it only changes the color of a particular column, and I would like it to change the color of all the columns of the same row.

DataGridView.CurrentRow.Cells[0].Style.BackColor = Color.Yellow;
    
asked by anonymous 02.10.2016 / 02:32

1 answer

2

Use dataGridView1.CurrentRow . DefaultCellStyle "and leave the dataGridView1 . SelectionMode = DataGridViewSelectionMode.FullRowSelect " which is the complete line selection:

dataGridView1.DataSource = new object[]
{
    new {Id = 1, Nome = "A"},
    new {Id = 2, Nome = "B"},
}
.ToList();

// configuração que marca a linha completa.
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView1.Update();
dataGridView1.Select();
// configuração do estilo da linha
dataGridView1.CurrentRow.DefaultCellStyle.BackColor = Color.Yellow;

References:

02.10.2016 / 02:58