JOPHIN MATHEW
JOPHIN MATHEW

Reputation: 11

datagridview color is not changing through validation

DataGridViewRow row = dataGridView1.Rows[1];
row.DefaultCellStyle.BackColor = Color.Red;

This code does not change the color if we apply in C#.net. let me know what's the problem?

Upvotes: 0

Views: 108

Answers (2)

sbecker
sbecker

Reputation: 584

You change the DefaultCellStyle.BackColor instead of the Style.BackColor which is the one actually used in the Paint event of the cells.

Changing your code to change the Style.BackColor of each cell in the row should do the trick.

foreach (DataGridViewCell cell in row.Cells) {
  cell.Style.BackColor = Color.Red;
}

You can find more information on how the DefaultCellStyle is used here.

Upvotes: 0

Fawzidi
Fawzidi

Reputation: 74

dataGridView1.RowsDefaultCellStyle.SelectionBackColor = Color.Red;

Upvotes: 1

Related Questions