DBGridEh添加序号列
//聲明全局變量i
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
with DBGrid1.DataSource.DataSet do
begin
if DataCol = 0 then //設置在第一列
begin
if state<>dsInsert then i:= recno; //這句是關鍵。。。
DBGrid1.Canvas.TextRect(Rect, Rect.Left + 2, Rect.Top + 2, IntToStr(i));
inc(i); //將i加1
end;
end;
end;
浙公网安备 33010602011771号