Reputation: 681
I am working on winform
C#
datagirdview
and I would like to change the color of a particular row in my datagridview
. The row should be changed to red when the value of columncell
is false.
Upvotes: 0
Views: 818
Reputation: 7092
Use the CellFormatting Event
private void dataGridView2_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == 1)
{
if (e.Value != null)
{
if ((bool)e.Value)
dataGridView2.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Blue;
else
dataGridView2.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Red;
}
}
}
EDIT:
The value of e.value
is base on the e.ColumnIndex
for more Details
Upvotes: 2