Add line number column to dbgrid


Add line number column to dbgrid

Create in dbgrid one column and insert the caption "RecNo" or other in title
property. 

In dbgrid onDrawColumnCell event insert the following code:

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  if Column.Title.Caption = 'RecNo' then
    DBGrid1.Canvas.TextOut(Rect.Left + 2, ect.Top,IntToStr(DataSource.DataSet.RecNo));

end;