求教cxgrid时间比较问题
cxgrid有一列是时间
数据库对应的类型是datetime
现在要求,与当前时间比较:
表中的时间-当前时间<=1的 cxgrid行显示红色
求高手帮忙,不胜感激,分有点少,但全部奉上
[解决办法]
在视图的重画事件中写代码:
procedure TDispatchStatForm.tvDListHeaderCustomDrawCell(
Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
ARect :TRect;
TableDate:TDatetime;
begin
ARect := AViewInfo.Bounds;
TableDate := AViewInfo.GridRecord.Values[ColumnName.Index];//ColumnName换成你表中在cxgrid中的列名。
if TableDate-Now<=1 then
ACanvas.Canvas.Font.Color := clRed
else
ACanvas.Canvas.Font.Color := clBlack;
ACanvas.Canvas.FillRect(ARect);
SetBkMode(ACanvas.Canvas.Handle,TRANSPARENT);
end;
[解决办法]
procedure TForm15.cxgrdbndtblvwCustomDrawCell(Sender: TcxCustomGridTableView;
ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo;
var ADone: Boolean);
var
vCurrDat : TDateTime;
begin
vCurrDat := AViewInfo.GridRecord.Values[2];
if vCurrDat > Now then
begin
ACanvas.Canvas.Brush.Color := clYellow;
end;
end;