I think this is what u need :
You make a new class who inherits from the System.Windows.Forms.DataGridTextBoxColumn
The only thing you change is the Paint event.
this is e.g. what u can do :
public class TestColumn : System.Windows.Forms.DataGridTextBoxColumn
{
public TestColumn()
{
//
// TODO: Add constructor logic here
//
}
protected override void Paint (
System.Drawing.Graphics Graph,
System.Drawing.Rectangle Bounds,
System.Windows.Forms.CurrencyManager Source,
int RowNr,
System.Drawing.Brush BackBrush,
System.Drawing.Brush ForeBrush,
bool AlignToRight)
{
DataRowView rowView = (DataRowView)Source.List[RowNr];
if (rowView["MyTestCol"]!=null)
{
string MyString = rowView["MyTestCol"].ToString();
switch (MyString)
{
case "1" :
ForeBrush=Brushes.Green;
break;
case "2" :
ForeBrush=Brushes.Black;
break;
case "3" :
ForeBrush=Brushes.DarkGreen;
break;
case "4" :
ForeBrush=Brushes.Brown;
break;
case "5" :
ForeBrush=Brushes.DarkSeaGreen;
break;
case "6" :
ForeBrush=Brushes.DarkSlateGray;
break;
default :
ForeBrush=Brushes.Black;
break;
}
}
base.Paint(Graph, Bounds,Source,RowNr,BackBrush,ForeBrush,AlignToRig ht);
}
}
It's a fast copy paste so there might be some "strange things" in the code :)
The next thing to do is something like this :
DataGridColumnStyle MyColumnStyle;
// Datum
MyColumnStyle = new TestColumn();
((DataGridTextBoxColumn)MyColumnStyle).Format="dd/MM/yyyy";
MyColumnStyle.MappingName="DatumVerrichting";
MyColumnStyle.HeaderText="Date";
MyDataGridTableStyleProductHistory.GridColumnStyle s.Add(MyColumnStyle);
It's my first reply so I hope this look better on the site then now in this box. Hope it helps at least ;)