gpt4 book ai didi

Delphi在DBGrid的Row前面添加图像

转载 作者:行者123 更新时间:2023-12-03 03:38:32 27 4
gpt4 key购买 nike

当我的数据源的 OnDataChange 事件出现错误时,我需要在 Row 前面添加 un image Alert。

enter image description here

我们怎样才能做到这一点?

最佳答案

我有以下起点:http://delphiexamples.com/databases/gridimages.html

这是我的修复建议。
在数据更改中,如果需要,请使用 tag 用错误代码标记字段。属性(property)。
来显示时间检查字段标记并根据需要显示位图。
我建议将位图存储在 ImageList 中;不要从数据库获取位图,它会无缘无故地破坏您的数据库。

procedure TForm1.DataSource1DataChange(Sender: TObject; Field: TField);
begin
if SomeCondition then Field.Tag:= Field.DataSet.RecNo
else Field.Tag:= 0;
end;

如果多行存在错误,则必须使用存在错误的外部行列表。一个TList<integer>就这个目的来说,效果很好。
在绘制方法中检查当前行是否在错误列表中。

Delphi 默认的 DBGrid 不方便绘制列标题和行标题。
然而它也不禁止它,所以你要在线条之外着色。

procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
var
index: integer;
begin
//Only draw one error per field.
//you might also want draw the error indicator in the field itself.
//and not in the row header.
if (Field.Tag = Field.Dataset.RecNo) and (Field = Table1Field1) then begin
//never mind the Rect we can draw where we like.
index:= 1;
ImageList1.Draw(DBGrdi1.Canvas, 2, Rect.Top, index, dsTransparent);
end
else DBGrid1.DefaultDrawDataCell(Rect, Field, State);
end;

关于Delphi在DBGrid的Row前面添加图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39272946/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com