I bind a DataGridView to a (List of ‘Payment’ objects) collection, I am using RowsAdded Event to Change the back color of the row depending on the status of the payment.
I am using (row.DefaultCellStyle.BackColor) to change the back color, But If I changed the color of the First row, then the color of the second row will be changed also, even though I did NOT change its back color.
and I don’t want to change its back color to (white) because there are some columns that have their own colors.
private void dgvPayment_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
DataGridViewRow row = dgvPayment.Rows[e.RowIndex];
Payment lPayment = row.DataBoundItem as Payment;
if (lPayment != null)
if (lPayment.IsLocked)
{
row.DefaultCellStyle.BackColor = Color.LightPink;
row.ReadOnly = true;
}
}
how to solve this ?
you can download the source code for here .
the problem is that when I put the backColor to white, the whole row will become white,I don’t want this , because there are a column(s) which have its own backColor.
As mentioned here (datagridview-defaultcellstyle-rows-and-columns-priority) :
So I Solved it like this;