读书人

DBGridEh单元格变色彩

发布时间: 2012-09-01 09:33:02 作者: rapoo

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; 

读书人网 >.NET

热点推荐