在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属性来显示文本,很简单吧
让我们考虑下面的例子:
我们有一个使用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属性来显示文本,很简单吧
相关文章推荐
- 如何根据判断数据的结果,改变DataGridView中对应记录的背景颜色?
- DataGirdView如何改变选中的CheckBox行的背景颜色:
- 如何改变treeview控件选中节点的高亮颜色,就是大家都熟悉的深蓝色,同样可以改变失去焦点时,高亮显示的颜色
- VS2008中如何改变对话框的背景颜色?...
- 控件容器如何点击后改变背景颜色(如LinearLayout...)
- Android如何让TextView子元素随着父元素的背景变化而改变字体颜色?
- ps如何改变物体颜色?PS替换颜色使用方法
- PS 如何改变一个icon的颜色
- 如何改变Win32 Console 程序显示颜色?
- 如何改变TextView的textColor的颜色或背景像radioButton一样简单。
- VC中如何改变对框中控件的颜色
- [Web开发] 如何改变IE滚动条的颜色
- 改变select下拉框中对应option的样式颜色已经展示的option如何进行颜色对应
- Win7系统下如何设置改变文本文档背景颜色
- 如何改变Android Progressbar默认颜色
- Unity3d 如何找到游戏对象并改变其颜色
- [Logstash] 如何找到并清空logstash-input-file插件的文件监控记录(sincedb)?
- 如何改变界面和非按钮控件的背景颜色
- MFC 如何改变对话框的默认背景颜色
- [导入]VC6.0中如何改变对话框的背景颜色