TADVStringgrid - Guide lines for sorting, filtering, columns moving, checkboxes, buttons, ect ect in one grid?

After 12 years, I'd think I'd know this, but I get bit every time!

Anyways...

Got A TADVStringgrid

It allows filtering.
It allows sorting.
It allows moving columns around.
It allows hiding columns
It has A single checkbox column.
It has A button column.

I can never remember the right way to reference cells in this case when A user moves everything around.

Always mix up when to use

Grid.RealRowIndex
Grid.RealColIndex
Grid.RealCells
Grid.Cells
Grid.AllCells
ect
ect
ect

Grid.HasCheckbox and Grid.IsChecked, which ACol / ARow to pass?

Honestly all of us here always get tripped up on this every single time.

We never remember what usage of things is to be used when and where.

So end up check boxing items, looping through, and getting wrong state on wrong cells.
Then in the loop, grabbing the wrong cell text.
Clicking something that triggers a Grid event, and knowing if the ACOL / AROW is exactly what we
need or if we need to translate to a real row/col/ or display row/col ,ect ect...

It is confusing at times....

It would be nice to have

  1. A really good guide line document for such grid designs that allow all this to happen.

  2. A really good demo that shows all this working together to use as a follow along.

I have 6 other developers that face this problem every time we gotta make a new grid and they would also like to have some good guide lines document / demo to show all this working to fall back onto when the time comes around again!

First guideline:
set grid.FilterType = ftSuppress and move the columns to be hidden as rightmost columns.
With this config, there is no row/column conversion to do between real & display indexes.

Second guideline:
If you can't use first guideline, in methods where you are expected to get/set the cell data, use the real indexes. In methods/events that relate to the visual cells, like cell rectangles, cell colors, ... use the display index.

First Guideline : Probably not doable? Since end users who want it to show later on want it to pop back up in the place it was originally... not at the very end... ? so probably have to write a bunch of stuff to try and move it all back to original positions?

Second Guideline : So something like this?

  col_ItemID := 6; /// original position when started out....
  // user drags it to somewhere say.. 2nd column visually on the screen
  // and user hide originally 2 first columns
..
..

  for idx := 1 to gridRelist.TotalRowCount - 1 do // is this right ? totalrowcount?
  begin
    rowCheck := gridRelist.RealRowIndex(idx) ; 
    if gridRelist.HasCheckBox(0, rowCheck) then
    begin
      if gridRelist.IsChecked(0, rowCheck) then
      begin
        col := gridRelist.realcolindex(col_ItemID);
        memoLines.add(girdRelist.AllCells[col, rowCheck]); // all cells? cells? displcells ?
      end;
    end;
 end;

It would still be nice to have a demo that wrapped all these features in to one program.
Something to fall back onto and if and when we get new developers, there is a demo to look at.

Right now all these grid features seem to be individual demos that show that single feature or two maybe...

The grid is a monster of a component... and very intimidating it seems with all it does and mixing up features to work together.

I overlooked the guideline that you can use grid.SuppressColumn() instead of grid.HideColumn() to avoid the real vs display column index and that with this mechanism, you do not need to move the columns to the rightmost position for hiding.