Issue with FilterDropDownCheck and OnGetDisplText

Hi,
I have an issue using the FilterDropDownCheck functionality with cells being filled with OnGetDisplText. When you apply a filter by checking some values on a column, the wrong results are shown. If you check and uncheck many times you might get lucky and finally get the expected date to be shown.

Also, with 2 FixedRows, the FilterDropDown ends up showing a blank line as the first choice when you use the filter at least 2 times.

Here is how to reproduce:
procedure TForm1.FormCreate(Sender: TObject);
begin
   AdvStringGrid1.FixedRows := 2;
   AdvStringGrid1.FilterDropDownAuto := True;
   AdvStringGrid1.FilterDropDownCheck := True;
end;

procedure TForm1.AdvStringGrid1GetDisplText(Sender: TObject; ACol, ARow: Integer; var Value: string);
begin
   if (Acol > 0) and (ARow >= 2) then
   begin
      Value := ARow.ToString + ACol.ToString;
   end;
end;


Help would be appreciated.

Thanks!

Do you use the latest version of the grid as I can't reproduce both things with the latest version.

Hi,
I am using the latest TMS Component Pack (7.9.0.1)
The grid version shows 7.8.0.0

I am using Delphi XE8 (not update 1).
Running on Windows 8 x64

I created a new project from scratch and I still get this issue.

Are you doing a runtime check you compile with the latest version 7.8.0.0?

Yes,
AdvStringGrid1.VersionString = 7.8.0.0 Jun, 2015
AdvStringGrid1.Version = 7.8.0.0
AdvStringGrid1.VersionNr.ToString = 117964800

Also, my target platform is Win32.

Hi,
I compiled my app in XE7 and I get the same problem.

Since you cannot reproduce is there a way I can upload a sample project?

Also just to be certain, here is again how I get I can reprocude this issue:
Start the project with the code I gave you.
Click the first column filter button.
Check a a value (you will get good result)
With the dropdown still open, check other values (you will get bad results)
From here on the date shown will be wrong.

If you can't see a problem juste play a lot with the checkboxes. You should notice the problem eventually but I always get the problem from the start. It's not random.

For the blank line I am talking about.
Start the project.
Click the first column filter button.
Check a a value
Close the dropdown
Reopen the same dropdown and you will see the empty blank line I am talking about.

Thanks


We could see the issue now but the issue is that you're trying to use this filtering in combination with virtual cells in a way the grid was conceptually not designed for. You just use the column & row coordinates for virtual cells but as you filter, these coordinates remain display coordinates and not the coordinates of the filtered cells. You'd need to convert the display coordinates to real coordinates (row) with the function grid.RealRowIndex()
But as you want to use this as well for getting the filter dropdown values, the coordinates will after filtering also be wrong for composing the filter. 

So, to workaround both issues, I'd suggest to fill the grid with row number indexes and use this cell value to retrieve the row from from the OnGetDisplText() event handler rather than the ARow parameter.

Hi,
I'm not sure I understand.
I added a row index column as you suggested but that doesn't solve the issue of filter not working.

Here is what I did and I still get both issue (filter not working and blank line):

procedure TForm1.FormCreate(Sender: TObject);
var
   i: Integer;
begin
   AdvStringGrid1.FixedRows := 2;
   AdvStringGrid1.FilterDropDownAuto := True;
   AdvStringGrid1.FilterDropDownCheck := True;

   for i := 0 to AdvStringGrid1.RowCount - 1 do
   begin
      AdvStringGrid1.Ints[0, i] := i;
   end;
end;

procedure TForm1.AdvStringGrid1GetDisplText(Sender: TObject; ACol, ARow: Integer; var Value: string);
begin
   if (Acol > 0) and (ARow >= 2) then
   begin
      Value := AdvStringGrid1.RealRowIndex(Arow).ToString + ACol.ToString;
   end;
end;

Could you please give me a code sample showing what you mean?

The dropdown is filled with good values (except for the blank line issue when you reopen it). It's when you check some of them that it acts strange.
For example, I run the project and for column 1 (leave dropdown open between steps):
Check 21 --> OK
Check 31 --> Not ok, only the row with value 21 is shown
Check the rest --> Not ok, only the row with value 21 is shown.
Once all the choices are checked, all rows are shown.
Now uncheck them backward
Uncheck 91 --> OK
Uncheck 81 --> Not ok, both 71 and 81 disapear

I understand how adding a row index column can solve this because the number of displayed rows is wrong.

Thanks

We further checked this and found a small issue in the grid itself. We fixed it and will release an update shortly. With this fix, following code will handle this properly (for column 4 filtering in this example):



procedure TForm1.AdvStringGrid1GetDisplText(Sender: TObject; ACol,
  ARow: Integer; var Value: string);
begin
 if (Acol > 0) and (ARow > 1) then
   begin
      Value := Value + '.' + IntToStr(ACol);
   end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
   i: Integer;
begin
   AdvStringGrid1.FixedRows := 2;
   AdvStringGrid1.FilterDropDownAuto := True;
   AdvStringGrid1.FilterDropDownCheck := True;

   for i := AdvStringGrid1.FixedRows to AdvStringGrid1.RowCount - 1 do
   begin
      AdvStringGrid1.Ints[4, i] := i;
   end;
end;

Hi,
I'm glad to hear this.

Just to be certain while you are fixing code in this section, I found two other issues with the FilterDropDownCheck.

I can even reproduce both issue without using virtual cells with the following code.:

* Notice that I hide a row #3 in the code.

procedure TForm1.FormCreate(Sender: TObject);
begin
   AdvStringGrid1.LinearFill;
   AdvStringGrid1.HideRow(3);
   AdvStringGrid1.FilterDropDownCheckUnCheckAll := 'Check/Uncheck all';
   AdvStringGrid1.FilterDropDownCheck := True;
   AdvStringGrid1.FilterDropDownAuto := True;
end;

1)
Open dropdown for column 1
Click the check all checkbox 2 times in a row (to select all and unselect all).
Row #3 is now visible. Should it not stay hidden?

2)
Open dropdown for column 1
Check in order: "1:1", "1:2", "1:4".
You should end up with an empty line for first row. <-- issue
Continue and uncheck the three checkbox.
Once all checkbox are unchecked, you end up with an extra empty row at the top. <-- issue


Will your fix cover those issues?

Thanks

Using filtering and hiding rows at the same time is mutually exclusive. Filtering relies on row hiding, so if you perform row hiding outside the internal processing of row hiding for filtering, this conflicts.