关于DataGrid的一些问题~~~能否解决???
bkss 2002-03-14 08:24:09 最恶心的就是:DataGridTextBoxColumn
这东西居然没有对字体方面的设置,比如想让某一列字为蓝色,就不知道该怎么办。
还有每个CELL开放的属性也太少,比如我要判断每项纪录中的第二列是否是负数,如果是负数那么该行用红色。这个问题很让人头大。
第一个问题我曾经重载过PaintText和Paint,结果也没有用。先将代码提供作为解决这个问题的高手们做参考。
public class dtGTextBoxCol : System.Windows.Forms.DataGridTextBoxColumn
{
public dtGTextBoxCol()
{
//
// TODO: Add constructor logic here
//
}
protected new void PaintText(Graphics g,Rectangle textBounds,string text,Brush backBrush,Brush foreBrush,bool alignToRight)
{
//
//重载对字体设置的方法
//
RectangleF rctf=new RectangleF(textBounds.Left,textBounds.Y,textBounds.Width,textBounds.Height);
Font fnt=new System.Drawing.Font("Arial",10,FontStyle.Bold);
Brush brush=new System.Drawing.SolidBrush(System.Drawing.Color.DarkKhaki);
g.DrawString(text,fnt,foreBrush,rctf);
}
protected new void Paint( Graphics g,Rectangle bounds,CurrencyManager source,int rowNum)
{
string text=source.List[rowNum].ToString();
RectangleF rctf=new RectangleF(bounds.Left,bounds.Y,bounds.Width,bounds.Height);
Font fnt=new System.Drawing.Font("Arial",10,FontStyle.Bold);
Brush brush=new System.Drawing.SolidBrush(System.Drawing.Color.DarkKhaki);
g.DrawString (text,fnt,brush,rctf);
}
}
唉,希望那位高手能帮忙解决一下哦。回家继续想。