第一步,把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属性来显示文本,很简单吧
让我们考虑下面的例子:
我们有一个使用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属性来显示文本,很简单吧