Change the color of the Datagridview line

Asked

Viewed 2,240 times

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 specific column, and I would like it to change the color of all columns in the same row.

DataGridView.CurrentRow.Cells[0].Style.BackColor = Color.Yellow;

1 answer

2


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

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:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.