Recent

Author Topic: First row in DBGrid  (Read 1458 times)

pcurtis

  • Hero Member
  • *****
  • Posts: 951
First row in DBGrid
« on: January 21, 2021, 06:20:06 pm »
Hi All,

How I set what row is displayed first in a datagrid? (not the selected row)

Thanks in advance.
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 586
    • Double Dummy Solver - free download
Re: First row in DBGrid
« Reply #1 on: January 22, 2021, 07:15:39 pm »
I think you're asking for DBGrid.TopRow
Lazarus 3.0RC2, FPC 3.2.2 x86_64-win64-win32/win64

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: First row in DBGrid
« Reply #2 on: January 23, 2021, 04:34:46 am »
OK, Im stupid, where is the TopRow property?
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 586
    • Double Dummy Solver - free download
Re: First row in DBGrid
« Reply #3 on: January 23, 2021, 07:49:39 am »
For example
   ShowMessage('The top row visible is: '+inttostr(Grid.TopRow));

Lazarus 3.0RC2, FPC 3.2.2 x86_64-win64-win32/win64

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: First row in DBGrid
« Reply #4 on: January 23, 2021, 01:05:38 pm »
What DBGrid are you using? The standard one in LCLBase does not have this property
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: First row in DBGrid
« Reply #5 on: January 23, 2021, 01:48:47 pm »
Please don't double-post. When nobody answers to your first post nobody will answer to the second one either. On the other hand when users do respond answers will be scatter between the two threads and the information may become useless to users seeing this discussion later.

I responded to the other thread (https://forum.lazarus.freepascal.org/index.php/topic,52971.msg391408.html#msg391408). To answer again in different words: Forget to use the DBGrid in the same way as you use the StringGrid. The dataset displayed in the grid determines what is seen and what can be done. For example you cannot navigate within the grid without navigating within the dataset, or to put it the other way round: You must navigate within the dataset if you want to change the active row.

When you absolutely need to know which record is displayed at the top of the grid you must query the internal buffer used by the grid which may be quite difficult because the buffer is not readily available. Or you must navigate the dataset back by the number of rows between the current and top row. You must take case not to confuse the user since this operation will normally scroll the grid. It would probably be easier to abandon the DBGrid and to switch to a StringGrid into which you read all the DB records (which can be come complicated when you have a huge DB accessed via network).

marcio2003

  • Jr. Member
  • **
  • Posts: 69
Re: First row in DBGrid
« Reply #6 on: January 23, 2021, 03:33:02 pm »
In some cases you can manipulate the search (Query) in the DB so that the desired record is at the top of the grid.
Lazarus 2.0.10 Windows 10 64bits

 

TinyPortal © 2005-2018