advStringGrid + advGridFilterPanel + selected rows problem

Please send any answers to paul.sinnema@wur.nl and NOT to harry.hamberg@wur.nl (he's our purchasing agent).

If I use an advStringGrid in combination with an advGridFilterPanel I get problems with (disjunct) rows that are alread selected in the grid.

The content of the grid is refreshed correctly according to the filter. The selected rows however remain in place and now encompass a completely different selection.

Can you try to set grid.FilterType = ftSuppress?

That solves the selection problem I describe but at the same time creates a new one. If I have a Filter active (via TAdvGridFilterPanel) and I select multiple rows then too many rows are selected. I guess all rows that are not visible but between f.i. 2 rows that are visible are also selected.

Filtering is very slow on large amounts of data with ftSuppress.

The filtering of the TAdvGridFilterPanel is also not working correcty with Dates. I've posted a question on StackOverflow here: delphi 10.4 sydney - TadvGridFilterPanel on TadvStringGrid filters dates wrong - Stack Overflow

I see there is a property IsSuppressedRow(row). Not completely clear now but that would help I guess.

I do think it's a bug that row that are suppressed and therefore not visible still can be selected. Do you agree?

  1. For filtering on dates, the date format for the filter condition needs to be the same as the date format used in the grid
  2. We'll look at the range selection issue when there are suppressed rows.

Hoi Bruno,

Added the code below and that solves it for me.

Regards,
Paul

/// <summary>
///   Don't allow suppressed rows to be selected.
/// </summary>
procedure TfrmPROJECTENBULKEDIT.ProjectenGridRowDisjunctSelect(Sender: TObject; ARow: Integer; AState: Boolean; var Allow: Boolean);
begin
  var grid        := TAdvStringGrid(Sender);

  Allow           := not grid.IsSuppressedRow(ARow);

end;

That is a valid solution at application level. We will also try to solve this at component level, so this application level solution is not longer necessary.

That's great Bruno. For now this works for me and I'm perfectly on schedule for delivering new functionality.

1 Like

About remark 1.

For filtering on dates, the date format for the filter condition needs to be the same as the date format used in the grid

I use the following code to fill the Dates in the grid.

  /// <summary>
  ///   Fills a cell with a date and sets its color.
  /// </summary>
  procedure lpFillCellDate(out col: integer; row: integer; date: TDate; valid: boolean = true);
  begin
    grid.Dates[col, row]      := date;

    lpSetColor(col, row, valid);

    inc(col);

  end;

TAdvFilterGridPanel is set to automatically use the information in the grid to populate the choices in the Field selector. I assumed that the routine would deduce from the fact that the grid.Dates[col, row] contains a date the filtering would use a compare of dates.

I also have this code in place:

  cColumnInfos      : array[0..12] of ColumnInfo =
                    (
                      (Header: 'Projectcode';           Width: 100; CellType: ssAlphabetic; EditorType: ceText),
                      (Header: 'Status';                Width: 50;  CellType: ssNumeric;    EditorType: ceNumeric),
                      (Header: 'Datum begin';           Width: 100; CellType: ssDate;       EditorType: ceDate),
                      (Header: 'Datum eind';            Width: 100; CellType: ssDate;       EditorType: ceDate),
                      (Header: 'Datum eind financieel'; Width: 150; CellType: ssDate;       EditorType: ceDate),
                      (Header: 'Controller';            Width: 150; CellType: ssAlphabetic; EditorType: ceText),
                      (Header: 'Acroniem';              Width: 100; CellType: ssAlphabetic; EditorType: ceText),
                      (Header: 'Projectcode extern';    Width: 150; CellType: ssAlphabetic; EditorType: ceText),
                      (Header: 'Administratie';         Width: 50;  CellType: ssNumeric;    EditorType: ceNumeric),
                      (Header: 'Titel';                 Width: 200; CellType: ssAlphabetic; EditorType: ceText),
                      (Header: 'Omschrijving';          Width: 200; CellType: ssAlphabetic; EditorType: ceText),
                      (Header: 'Aanvrager';             Width: 150; CellType: ssAlphabetic; EditorType: ceText),
                      (Header: 'Datum uitgifte';        Width: 150; CellType: ssDate;       EditorType: ceDate)
                    );

/// <summary>
///   Set the editor type.
/// </summary>
procedure TfrmPROJECTENBULKEDIT.gfpProjectFilterGetEditorType(Sender: TObject; ACol: Integer; var AEditorType: TColumnEditor);
begin
  AEditorType := cColumnInfos[ACol].EditorType;

end;

/// <summary>
///   Set the cell type.
/// </summary>
procedure TfrmPROJECTENBULKEDIT.ProjectenGridGetFormat(Sender: TObject; ACol: Integer; var AStyle: TSortStyle; var aPrefix, aSuffix: string);
begin
  AStyle := cColumnInfos[ACol].CellType;

end;

Storage internally in the grid is string based, so the date format is important and should be the same for cell & filter condtion.

Ok, can you give me hint where to find this in the documentation?

I've looked here:

.. and the only place I find mention of Date is in the Description:

Description
TAdvGridFilter & TAdvDBFilter are extensions for TAdvStringGrid and TDataSet to provide step by
step visual filtering capabilities to the grid.
The TMS TAdvGridFilter & TAdvDBFilter are easy to use components designed to filter different
kinds of data. From financial and marketing data to monthly business sales, graphical and educative
math data. The visual user interface supports column data types such as numeric, text, date and
boolean. The filter can be shown in normal mode (panel on the form) or in dialog mode.

And there's no mention of Format anywhere.

We assumed that throughout an application a consistent date formatting would be used.

I read in another ticket that the grid takes the date formatting from FormatSettings. So does our application. In other words formatting is already the same. But it still doesn't filter correctly. I'll investigate a little deeper.