您的位置:首页 > 其它

在DBGird中如何改变记录的颜色

2007-03-27 12:40 405 查看
第一步,把DefaultDrawing属性设置为False.
    让我们考虑下面的例子:
 我们有一个使用CachedUpdates的dataset。而用户需要知道哪些记录是已经编辑过的,哪些是新的和哪些是已经删除的。
 上述讲到的CachedUpdates可以用UpdateStatus函数进行设置。为了要从dateset中显示被删除的记录(在确认更新之前),我们要修改UpdateRecordTypes属性。该属性详细地描述了哪些记录将要在dataset中显示出来--默认为[rtModified, rtInserted, rtUnmodified]。
 因此,在我们的代码中要加入下面的一行:
UpdateRecordTypes := UpdateRecordTypes + [rtDeleted];
 现在让我们为DBGrid的OnDrawColumnCell事件添加下面的代码;
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  with (Sender as TDBGrid).Canvas do begin
    case (DataSource.DataSet as TBDEDataSet).UpdateStatus of
      usInserted : Brush.Color := clRed;
      usModified : Brush.Color := clBlue;
      usDeleted  : begin Brush.Color := clBlack; Font.Color := clWhite; end;
    end;
    DefaultDrawDataCell(Rect, Column.Field, State);
  end;
end;
 DefaultDrawDataCell现在将会用新的font和brush属性来显示文本,很简单吧  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  dataset integer