Delphi 使用TMS TDBAdvGrid,如何根据单元值为具有不同颜色的线着色?

Delphi 使用TMS TDBAdvGrid,如何根据单元值为具有不同颜色的线着色?,delphi,tms,Delphi,Tms,一切都在标题中。 我们如何使每一行的officehint都可以定制。当鼠标移动到一行时,显示此记录的信息(来自db查询) 谢谢您可以使用网格的CellProperties属性为单个单元格着色。可以使用此选项为整行着色: var RowIndex: Integer; ColIndex: Integer; with MyDBAdvGrid do begin // you choose the row index; you may want to iterate all rows to

一切都在标题中。 我们如何使每一行的officehint都可以定制。当鼠标移动到一行时,显示此记录的信息(来自db查询)


谢谢

您可以使用网格的
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;

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

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;

谢谢,但是当你告诉手机的时候,你指的是什么事件?一些事件表明数据发生了变化。这取决于如何使用网格。关于这件事有这么多的事件…谢谢,但这样它只在我单击行时显示颜色。是否可以在不移动光标的情况下执行相同的操作?Thakns您可能需要考虑AState属性。