首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

DBGridEh单元格变色彩

2012-09-01 
DBGridEh单元格变颜色向大家请教:现在我一个表,在DbGridEh里显示,我想对此表进行检验,然后把此表中不符合

DBGridEh单元格变颜色
向大家请教:
  现在我一个表,在DbGridEh里显示,我想对此表进行检验,然后把此表中不符合条件的单元格进行变色,以显区分.
  例如:有的表里有数据
  姓名 数学分 英语分 物理分 化学分
  第一条: 张三 80 45 57 70
  李四 43 75 61 50
  王五 99 87 90 55
  把所有不及格的信息进行颜色区分。请大侠门帮忙!
 

[解决办法]

Delphi(Pascal) code
procedure TForm1.DBGridEh1DrawColumnCell(Sender: TObject;  const Rect: TRect; DataCol: Integer; Column: TColumnEh;  State: TGridDrawState);begin{数学分 英语分  物理分  化学分} if (ADOQuery1.FieldByName('数学分').AsInteger <60) and    (ADOQuery1.FieldByName('英语分').AsInteger <60)  and    (ADOQuery1.FieldByName('物理分').AsInteger <60)  and    (ADOQuery1.FieldByName('化学分').AsInteger <60) then begin   if (State = [gdSelected]) or (State = [gdSelected, gdFocused]) then      DBGridEh1.Canvas.Font.Color := clYellow     else     DBGridEh1.Canvas.Font.Color := clGreen;   DBGridEh1.DefaultDrawColumnCell(Rect, DataCol, Column, State); end;end;end; 

热点排行