To change color of DataGridView Cell depanding on the value of Databound Item.
DataGridView DataSource is collection of custom object 'SomeClass'
public class SomeClass
{
public bool PropertyName { get; set; }
.
.
.
}
private void dataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (dGV.Columns[e.ColumnIndex].Name == nameof(SomeClass.PropertyName))
{
var dataItem = dGV.Rows[e.RowIndex].DataBoundItem as SomeClass;
if (!dataItem.PropertyName)
e.CellStyle.BackColor = Color.Red;
}
}
Comments
Post a Comment