⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 使dbgrid的某几笔资料变色.txt

📁 大量Delphi开发资料
💻 TXT
字号:
使dbgrid的某几笔资料变色



你可在 DBGrid 元件的 DrawDataCell 事件中

依资料的条件性来改变格子或文字的

颜色.


如 :


OnDrawDataCell(...)

begin

with TDBGrid(Sender) do

begin

if (条件) then

Canvas.TextOut(Rect.Left + 4

Rect.Top + 2

'要显示的文字

如表格的资料');

end;


而你会看到 DBGrid 的显示资料怎麽有重叠的情况

那是因为原本DBGrid

要显示的资料与 TextOut 所显示的资料重叠

解决方法 :


在 Query 元件所加入的栏位(在元件上按右键

会有 Add Fields...的选单)


不要显示资料的栏位的 OnGetText 事件中有一参数设定为 False;


procedure TForm1.Query1Detail1GetText(Sender: TField; var Text: string;

DisplayText: Boolean);

begin

// 决定在 DBGrid 得知表格资料时

要不要显示所得到的资料

False -> 不显示

// 就可避免与 TextOut 的文字重叠了

DisplayText : = False;

end;


end;




如果用 Delphi 3 处理很简单.


例如

对表中某字段当其数值小于0时为红字

其他为黑字.

在 DBGrid.OnDrawColumnCell(...) 中:

begin

if TableField.AsInteger < 0 then

DBGrid.Canvas.Font.Color := clRed

else

DBGrid.Canvas.Font.Color := clBlack;


DBGrid.DefaultDrawColumnCell(...);

end;


这样

对 Field 指定的格式仍旧生效

不必重写.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -