使用 TMS TDBAdvGrid,如何根据单元格值使用不同颜色的线条?

发布于 2024-11-30 11:16:22 字数 86 浏览 1 评论 0原文

一切都在标题中。 我们怎样才能为每一行定制一个 Officehint 呢?意思是当鼠标移动到一行时,显示该记录的信息(来自数据库查询)。

谢谢

All is in the title.
How can we also make an officehint customisable for each row. Mean when mousemove on a row, display the information of this record (from a db query).

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

流殇 2024-12-07 11:16:22

您可以使用网格的 CellProperties 属性为各个单元格着色。您可以使用它来为整行着色:

var
  RowIndex: Integer;
  ColIndex: Integer;

with MyDBAdvGrid do
begin
  // you choose the row index; you may want to iterate all rows to 
  // color each of them
  RowIndex := 2;
  // now iterate all (non-fixed, visible) cells in the row and color each cell
  for ColIndex := FixedCols to ColCount - 1 do
  begin
    CellProperties[ColIndex, RowIndex].BrushColor := clYellow;
    CellProperties[ColIndex, RowIndex].FontColor := clGreen;
  end;
end;

要使用记录数据填充您的办公室提示,我建议在用户移动鼠标时更新它。使用MouseToCell函数获取鼠标下的行和列,然后使用MyDBAdvGrid.AllCells[ColIndex, RowIndex]访问单元格内容。

You can color individual cells using the CellProperties property of the grid. You can use this to color an entire row:

var
  RowIndex: Integer;
  ColIndex: Integer;

with MyDBAdvGrid do
begin
  // you choose the row index; you may want to iterate all rows to 
  // color each of them
  RowIndex := 2;
  // now iterate all (non-fixed, visible) cells in the row and color each cell
  for ColIndex := FixedCols to ColCount - 1 do
  begin
    CellProperties[ColIndex, RowIndex].BrushColor := clYellow;
    CellProperties[ColIndex, RowIndex].FontColor := clGreen;
  end;
end;

To fill your office hint with record data I would suggest updating it when the user moves the mouse. Use the MouseToCell function to get row and column under the mouse, then use MyDBAdvGrid.AllCells[ColIndex, RowIndex] to access the cell content.

不可一世的女人 2024-12-07 11:16:22

Heinrich 答案的替代方法是使用 OnGetCellColor 事件。

这可以像这样使用:

procedure TDBAdvGrid.DBGridGetCellColor(Sender: TObject; ARow,
  ACol: Integer; AState: TGridDrawState; ABrush: TBrush; AFont: TFont);
begin
     if (your condition) then ABrush.Color := clRed;
end;

类似地对于提示:

procedure TDBAdvGrid.DBGridGridHint(Sender: TObject; ARow, ACol: Integer;
  var hintstr: String);
begin
    hintstr := 'your hint text';
end;

An Alternative to Heinrich answer is to use the OnGetCellColor event.

This can be use like so:

procedure TDBAdvGrid.DBGridGetCellColor(Sender: TObject; ARow,
  ACol: Integer; AState: TGridDrawState; ABrush: TBrush; AFont: TFont);
begin
     if (your condition) then ABrush.Color := clRed;
end;

Similarly for the hint:

procedure TDBAdvGrid.DBGridGridHint(Sender: TObject; ARow, ACol: Integer;
  var hintstr: String);
begin
    hintstr := 'your hint text';
end;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文