delphi - 在显示之前修改 DBGrid 单元格内容

标签 delphi dbgrid

我想在加载数据库时修改 dbgrid 控件中特定单元格的内容。例如,假设我不希望数据库的任何字段在 dbgrid 中显示,如果它等于“forbidden”。有什么办法可以做到这一点吗?

最佳答案

转到你原来的问题:

使用字段的 OnGetText 事件提供与数据库中存储的值不同的值以用于演示目的。

如果需要将该值呈现给用户,则 DisplayText bool 参数将为 True;如果需要将该值用于其他目的,则该 bool 参数将为 False。

procedure TForm1.SQLQuery1Field1GetText(Sender: TField; 
  var Text: string; DisplayText: Boolean);
begin
  if (Sender.AsString = 'forbidden') and (DisplayText) 
    and (PrivilegeLevel(CurrentUser) < 10) then
    Text := '********'
  else
    Text := Sender.AsString;
end;

关于delphi - 在显示之前修改 DBGrid 单元格内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4902641/

相关文章:

mysql - Delphi双击DBGrid查找行的字段内容

delphi - dbgrid 自动适应表单

delphi - 数据库网格: How to use a column of the current row of one as an index into another?

mysql - 合并 DBGrid 列值

delphi - 在Delphi中将UTC字符串转换为TDatetime

delphi - 如何获取我的磁盘分区的 GUID?

windows - WUA API 无法卸载更新

delphi - 记录类型中的绝对寻址字段

android - Delphi XE7 TBannerAd 未在 Android 上显示广告

delphi - DBGrid - 如何设置单独的背景颜色?