Add line number column to dbgrid

Submitted by:Andery Smith

Date added:12 March, 2012

Category:Delphi

Create in dbgrid one column and insert the caption "RecNo" or other in title property.
In dbgrid onDrawColumnCell event insert the following code:

Tags: dbgrid

Code Snippet:

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;
 
 

Comments