DBGrid onDrawColumnCell Scroll up messes order of records lazarus / 16-Databases ---------------------------------------------------------------------- Jkey · 2017-02-09 15:12 Hello, I use DBGrid's onDrawColumnCell event to show row numbers there: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);begin  if (DataCol = 0) then    DBGrid1.Canvas.TextOut(Rect.Left + 2, Rect.Top, IntToStr(DBGrid1.DataSource.DataSet.RecNo));end;At a first glance it seems to work, but when I scroll down the DBGrid, and start to scroll it up by either mouse wheel or arrow up key of keyboard, it won't go up and starts repeating records strangely from lower sections. You can find attached a very small zip packed demo project to be able to reproduce the issue. I was able to reproduce it using Lazarus 1.6.2 on both Windows 7 x86 and Ubuntu x64. Demo contains a simple SQLite database as source of data to display. If I comment out the contents of onDrawColumnCell event, DBGrid will start behaving normally again, but I would loose the rowIDs. Is there any other way to show RowIDs in DBGrid?Or do you have ideas, how I can solve the strange issue of scrolling up?Thank you in advance. ---------------------------------------------------------------------- Jkey · 2017-02-09 21:08 Anyone who face with this issue in the future, here is my workaround: Create a dummy SQLQuery.BeforeScroll event and read the value of Dataset.RecNo. Then do nothing with it, and that's all. Since then both dataset scrolling and DBGrid onDrawColumnCell with displaying row numbers work as expected. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.SQLQuery1BeforeScroll(DataSet: TDataSet);var  i: longint;begin  i := DataSet.RecNo;end; ---------------------------------------------------------------------- marcio2003 · 2017-02-09 22:21 I think you want use fixed column(zero) to go numbering the lines. Is it? ---------------------------------------------------------------------- Jkey · 2017-02-10 08:26 Yes. My provided code (in my first post) can do it. But when I scrolled my DBGrid (mainly to up direction), records used to get mixed strangely. Declaring a dummy BeforeScroll event (my second post) fortunately somehow prevents this issue to happen, and everything is OK.