I have several DataGridViews where I would like to color the text of
certain columns depending on their content. For example, if in
column1, the text of a cell is "High" that should be colored red, or
green if the text is "Low".
Right now, I have a handler attached to the Grid's CellFormatting
event, that works like this:
void DataGrid_CellFormatting(object sender,
DataGridViewCellFormattingEventArgs e) {
if (e.ColumnIndex == 0) {
if (e.Value.ToString() == "High") {
e.CellStyle.ForeColor = Color.Red;
} else {
e.CellStyle.ForeColor = Color.Green;
}
}
}
This can get quite large, however, and I wondered if there is a better
way of doing this. Also, this isn't flexible at all, and I would like
something a little more manageable.
Anyone have any tips or suggestions?
Thanks,
Matt