|
发表于 2020-4-8 14:00:01
|
显示全部楼层
重写datagird的onpaint函数,而且要使用dataGridTableStyle.大致如下
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);
}
}
}
用这个类代替DataGridTextBoxColumn来定义变量:如下
private DataGridColoredTextBoxColumn IDColumn;
就可以了。
|
|