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

求教cxgrid时间比较有关问题

2013-08-09 
求教cxgrid时间比较问题cxgrid有一列是时间数据库对应的类型是datetime现在要求,与当前时间比较:表中的时

求教cxgrid时间比较问题
cxgrid有一列是时间
数据库对应的类型是datetime

现在要求,与当前时间比较:
表中的时间-当前时间<=1的 cxgrid行显示红色

求高手帮忙,不胜感激,分有点少,但全部奉上求教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;

热点排行