TMS TDBAdvGrid & PageMode

code

  • TDBAdvGrid with PageMode property set true
    This is the default mode for TDBAdvGrid. With PageMode = true, the behaviour of TDBAdvGrid most closely resembles the behaviour of the standard VCL TDBGrid. This means that TDBAdvGrid only loads the rows from the connected dataset that are visible. The grid will load a new page of rows when it is scrolled to a previous or next page. As the grid loads the minimum number of rows that is simultaneously required for display, this is the fastest mode. A disadvantage of this mode is that not all rows are simultaneously available for operations like searching, grouping, filtering, sorting, export, printing,...
  • TDBAdvGrid with PageMode property set false
    When PageMode is false, all rows of the dataset are loaded in the grid when the dataset is activated. This can have an initial performance hit for large datasets. After all data is loaded from the dataset, the grid is disconnected from the dataset. The full base class TAdvStringGrid operations on the data can now be directly executed. A disadvantage is that the grid will not operate synchronously with the dataset cursor and cannot edit the dataset. It will depend on the requirements of your applications what mode is recommended. For typical reporting scenarios where user just needs to view, sort, print, export data the grid with PageMode set to false is adequate and operates with minimum amount of code to add. For scenarios where data should be editable, where a dataset cursor is important, where a very large dataset is used, ... it is recommended to use TDBAdvGrid with PageMode set to true.
The PageMode property was not designed to be switchable while the dataset is active.


The scrollbar is only limited to three positions

This behavior is caused by the dataset. When grid.PageMode = true and DataSetType = dtNonSequenced the grid only displays a buffer of visible records, the grid has no information at all where this buffer is positioned in the database except that it is the first buffer, last buffer or not the first or last buffer. Hence, there are only 3 possible scrollbar positions.
When you set grid.PageMode = false, the grid loads & shows all records and can thus show an exact scrollbar position.

After updating the ClientDataSets, data is missing in the grid and several rows are blank

Make sure that grid.PageMode = true and that grid.DataSetType = dtNonSequenced. That should improve the performance. This is also explained at page 6 of the TDBAdvGrid developers guide
Other than the column properties, some other settings need to be considered. With PageMode set to true, some datasets maintain internally an order for returning the pages of displayed rows to the grid and some not. This depends on the implementation of the TDataSet component that is used to connect to the database of choice. In general, when there is a problem with scrolling in the grid, it is recommended to set the property DataSetType to dtNonSequenced.

Filtering and sorting in TDBAdvGrid

If you want to use the built-in sorting capabilities of the grid, you need to set grid.PageMode= false. This way, you can use the same capabilities to filter as for a TAdvStringGrid. Alternatively, perform the filtering on your dataset. With dataset filtering, you can leave TDBAdvGrid.PageMode = true. Please have a look at the demos ADOSort / BDESort in the TDBAdvGrid samples distribution as well as the topic on sorting in the TDBAdvGrid developers guide that explains how you can use the OnCanSort event to achieve this.

Grouping in TDBAdvGrid

PageMode = false is a requirement for grouping.

Changing the DB cursor

It is by design that when grid.PageMode = false, the grid will not automatically move the DB cursor when selecting rows. If you need this functionality and you have a DB key field in the grid, implement the OnSelectCell event, from this event get the DB key value via grid.Cells[col,row] and use DataSet.Locate to move the DB cursor to this selected record.

Disjunct row selection in TDBAdvGrid

The built-in feature disjunct row selection requires that grid.PageMode = false

When grid.PageMode = true, the disjunct row selection cannot work. In this mode, only the records that are visible are displayed in the grid, no other rows are loaded in the grid. It is unfortunately not possible to keep the selection state for rows that are not loaded/visible in the grid.

TDBAdvGrid.SelectRows

Please set TDBAdvGrid.PageMode = false to use this functionality.

Getting the cell value of TDBAdvGrid

When grid.PageMode = true, grid.Cells[col,row] only has the visible records, not visible records are not loaded and therefore not accessible. Either loop through the dataset (dataset.First / dataset.Next) to get the values via dataset.Fields[] or set grid.PageMode = false and then you can access all rows via grid.Cells[col,row]

Drag & drop in TDBAdvGrid

If you set grid.PageMode = false, the drag & drop in TDBAdvGrid will behave exactly the same as in sample 28 at: https://www.tmssoftware.com/site/asg28.asp

TAdvGridFindDialog

TAdvGridFindDialog is designed to be used with a grid in PageMode = false. When you have grid.PageMode = true, it is recommend to perform a locate in the dataset directly from where you enter the search condition.

TAdvGridLookupBar

PageMode = false is a requirement for TAdvGridLookupBar.

Grid.FloatingFooter.ColumnCalc

When grid.PageMode = false, you can use Grid.FloatingFooter.ColumnCalc. It is by design that this is not supported when PageMode = true as in this mode, the grid doesn't have all records all the time loaded, hence, it can't calculate a total.

Update a single row

When PageMode = false, it is not possible to update a single row. You need PageMode = true for this. To update the grid when PageMode = false, call grid.Refresh;

Sync scroll feature

You cannot use the sync scroll feature between a DB grid and a non DB grid when the DB grid has PageMode = true. This is by design and normal because when PageMode = true, the DB grid has only the visible nr. of rows, i.e. a scroll is not really a scroll with the entire set of rows (like in the non DB grid) A possible solution would be to set TDBAdvGrid.PageMode := false

Images

You can have a look at the demo app ADODataImage. This shows a TDBAdvGrid with data images with grid.PageMode = true

AutoSizeRows

To have AutoSizeRows applied to all rows, you need to set grid.PageMode = false. When PageMode = true, the grid does not have all records, only those visible, hence, it can't apply auto sizing to all rows.

Refresh

By design, when grid.PageMode = false, it won't automatically reload/refresh data when the dataset changes. With grid.PageMode = false, you would need to force this programmatically by calling TDBAdvGrid.Reload;

goRowMoving/goColMoving/goRowSelect

In order to be able to use row rearranging in the grid, please make sure that grid.PageMode = false

grid.Colors[col,row]

When your grid is in PageMode = true, you should not set colors via grid.Colors[col,row] but only via the event OnGetCellColor. In the OnGetCellColor event, you should always reference the DB field values via grid.Cells[col,row]; In PageMode = true, you can't use directly accessing the grid.Colors[] property as the grid only has cells to display a buffer of data from the database and will as such always use row 1 to display the first record of this buffer, i.e. row 1 can hold database record 1 but also 10, 20, etc...