【问题标题】:Extending DBGrid with some row colors用一些行颜色扩展 DBGrid
【发布时间】:2012-03-26 02:53:47
【问题描述】:

我想扩展 DbGrid 功能以在奇数行和偶数行上添加颜色。所以我写了这个

procedure TGridx.DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState);
var
  row : Integer;
begin
   inherited;
  row := Self.DataSource.DataSet.RecNo;
  if (row mod 2 = 0) then
    Self.Canvas.Brush.Color := FColor1  //some color
  else
    Self.Canvas.Brush.Color := FColor2; //some color

end;

我做错了什么?

【问题讨论】:

  • 试试this。您可能想在事件退出之前使用inherited,或者尝试调用DefaultDrawColumnCell
  • 我都试过了,我无法调用 DefaultDrawColumnCell,因为我正在重写一个没有该函数参数的方法

标签: delphi components delphi-7


【解决方案1】:

你想要的事件被称为DBGridDrawColumnCell,你需要决定是打开还是关闭DefaultDrawing属性,你处理DBGridDrawColumnCell的方式也会相应改变。对于您的情况,您只需设置颜色,但将 DefaultDrawing 保留为 true,并且不要执行任何其他 canvas.Text 或 GDI 绘图。

我最近问过here 的一个问题表明,在以后的 Delphi 版本(2010、Xe、Xe2)中,当在 ownerdraw 事件中更改画布属性时,您有时还需要为 TDBGRID 和 TListView 调用Canvas.Refresh,但这并不t 适用于 delphi 7。

【讨论】:

    【解决方案2】:

    您也应该尝试免费的 3d 派对解决方案,并且已经扩展了很多 DBGrid,就像 Jedi project 提供的那样

    【讨论】:

    • 它也有在线搜索吗?我的意思是,如果你按一个键,它会到达那个字母吗?
    【解决方案3】:

    Opc0de,也许你应该覆盖的不是“DrawCell”方法而是“DrawCellBackground”?

    【讨论】:

    • 在基类中找不到 DrawCellBackground
    • 您使用的是哪个 Delphi 版本?
    • 对不起,我帮不上忙。我没有 Delphi 7。显然 7 和 XE 之间存在差异 :)
    【解决方案4】:

    在定义画笔颜色后尝试绘制单元格:

    Self.Canvas.FillRect(ARect);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-31
      • 1970-01-01
      • 1970-01-01
      • 2020-03-13
      • 1970-01-01
      • 2014-06-01
      • 1970-01-01
      • 2018-04-10
      相关资源
      最近更新 更多