Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi为DBGrid在行前面添加图像_Delphi_Datasource_Dbgrid - Fatal编程技术网

Delphi为DBGrid在行前面添加图像

Delphi为DBGrid在行前面添加图像,delphi,datasource,dbgrid,Delphi,Datasource,Dbgrid,当我的数据源的OnDataChange事件出错时,我需要在行的前面添加un图像警报 我们如何做到这一点?我有以下出发点: 以下是我的修复建议。 在数据更改中,如果需要,使用标记属性在字段中标记错误代码。 来显示时间检查字段标记,如果需要,显示位图。 我建议将位图存储在ImageList中;不要从数据库中获取位图,它会无缘无故地攻击数据库 procedure TForm1.DataSource1DataChange(Sender: TObject; Field: TField); begin

当我的数据源的
OnDataChange
事件出错时,我需要在行的前面添加un图像警报


我们如何做到这一点?

我有以下出发点:

以下是我的修复建议。
在数据更改中,如果需要,使用
标记
属性在字段中标记错误代码。
来显示时间检查字段标记,如果需要,显示位图。
我建议将位图存储在ImageList中;不要从数据库中获取位图,它会无缘无故地攻击数据库

procedure TForm1.DataSource1DataChange(Sender: TObject; Field: TField);
begin
  if SomeCondition then Field.Tag:= Field.DataSet.RecNo
  else Field.Tag:= 0;
end;
如果可以有多个错误行,则必须使用外部错误行列表。
t列表
可以很好地用于此目的。
在draw方法中,检查当前行是否在错误列表中

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;

那对我有帮助。。非常感谢。不,在约翰的回答中,
DrawDataCell
似乎还不完整!