Record number in column 0?

I tried this code but it prints the current selected record in every cell in column 0. What am i doing wrong?


procedure Torderlist.DBAdvGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
  if dbadvgrid1.DataSource.DataSet.Active = false then exit;

  if dbadvgrid1.DataSource.DataSet.RecNo > 0 then
    begin
      if acol = 0 then dbadvgrid1.Canvas.TextOut(rect.Left + 5, rect.Top, inttostr(dbadvgrid1.DataSource.DataSet.RecNo));

    end;
end;

The selected record doesn't change during painting of the grid, so DataSource.DataSet.RecNo doesn't change. The index of the record in the dataset can be retrieved via grid.Row

I don't think I'm going about this the right way.  I have tried a few things and the result is that the first visible row is always number 1, then 2 and so on when you scroll vertically.  So that is not what i want.
What i am trying to do is the users want the column zero to have a record number in it so if they scroll the screen left and right, they still have an indicator of what record they are reading.  Meaning 1 to record count for the number of rows returned in that detail result.  Do you have a suggestion for this?  I could make column 1 in the grid the id key field, but that number will grow over time and look goofy.  The typical results for these grids will return 300 records or less based on the master/detail link.

I also tried counting through rows in the grid with 

for I := 1 to dbadvgrid1.RowCount-1 do dbadvgrid1.Cells[0,i] := inttostr(dbadvgrid1.Row); 
and putting
dbadvgrid1.Cells[0,dbadvgrid1.Row] := inttostr(dbadvgrid1.Row);
in the rowupdate and paint, but results are still no good.  seems to only count the number of rows visible at that time, not the record number.
Any ideas?  I just want the rows numbered in column zero 1 to record count so that it is a static visual indicator of what row they are reading if they scroll the grid left and right.

Have you tried to use the event OnGetDisplText() and return from this event handler for the first column the record number? Alternatively, you could add a calculated field to the dataset that returns the record number and display that calculated field in a grid column.

I tried that and several other places but the numbers do not stay with the records.  They only care about the rows in the grid that are displayed.