|
Rewrite the onpaint function of datagird, and use dataGridTableStyle. Roughly as follows
public class DataGridColoredTextBoxColumn: DataGridTextBoxColumn
{
public DataView dv = null;
protected override void Paint (Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, Brush backBrush, Brush foreBrush, bool alignToRight)
{
try
{
switch (dv [rowNum] .Row [3] .ToString ())
{
case "critical": backBrush = Brushes.Red; break;
case "major": backBrush = Brushes.Red; break;
case "minor": backBrush = Brushes.Orange; break;
case "warning": backBrush = Brushes.Orange; break;
default: break;
}
}
catch (Exception ex)
{
MessageBox.Show (ex.Message);
}
finally
{
base.Paint (g, bounds, source, rowNum, backBrush, foreBrush, alignToRight);
}
}
}
Use this class instead of DataGridTextBoxColumn to define variables: as follows
private DataGridColoredTextBoxColumn IDColumn;
That's it. |
|