Blog Home  Home Feed your aggregator (RSS 2.0)  
.Net Jonesie - DataGridView CellFormatting funkinisity
A simple programmers blog
 
 Monday, July 04, 2005

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. 

Monday, July 04, 2005 4:20:14 PM (New Zealand Standard Time, UTC+12:00)  #    Comments [1]    |   | 
Copyright © 2009 Peter G Jones. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.