I'm trying to format contents of a cell in a DataGridView using the following code:
private void RosterGrid_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
ShiftCell sc = e.Value as ShiftCell;
if (sc != null && sc.RosteredShiftRow != null)
{
if (!sc.RosteredShiftRow.ShiftRow.IsForegroundColorNull())
e.CellStyle.ForeColor = Color.FromArgb(sc.RosteredShiftRow.ShiftRow.ForegroundColor);
if (!sc.RosteredShiftRow.ShiftRow.IsBackGroundColorNull())
e.CellStyle.BackColor = Color.FromArgb(sc.RosteredShiftRow.ShiftRow.BackGroundColor);
e.Value = sc.ToString();
//e.FormattingApplied = true; // tried this and it make no diff
}
}
This should set the current cell colours for some cells only.
However the result is crap:

Anyone got any ideas?
Update: I fixed this by making sure I set the background colour to something valid. Sometimes is was being set to 0 and other times it was not being set at all. Now I either set both colours or none and it works really well.