TAdvStringGrid.ExpandNode unhides too many rows

There is a bug in procedure TAdvStringGrid.ExpandNodeInt of unit AdvGrid.pas which unhides too many rows in some cases.

Here is an example:


  AdvStringGrid1.InsertRows(AdvStringGrid1.RowCount, 9 - AdvStringGrid1.RowCount + 1);
  AdvStringGrid1.Cells[1,1] := '1';
  AdvStringGrid1.Cells[1,2] := '1.1';
  AdvStringGrid1.Cells[1,3] := '1.2';
  AdvStringGrid1.Cells[1,4] := '2';
  AdvStringGrid1.Cells[1,5] := '3';
  AdvStringGrid1.Cells[1,6] := '3.1';
  AdvStringGrid1.Cells[1,7] := '3.2';
  AdvStringGrid1.Cells[1,8] := '4';
  AdvStringGrid1.Cells[1,9] := '5';

  AdvStringGrid1.AddNode(1,3);
  AdvStringGrid1.AddNode(5,3);

  AdvStringGrid1.ContractNode(1);
  AdvStringGrid1.HideRow(4);
  AdvStringGrid1.ContractNode(5);
  AdvStringGrid1.HideRow(8);
  AdvStringGrid1.HideRow(9);

  AdvStringGrid1.ExpandNode(1); // expands '1.1' and '1.2', but also node '2'

  AdvStringGrid1.ExpandNode(5); // expands '3.1' and '3.2', but also nodes '4' and '5'



I patched lines 15515 until 15525 in AdvGrid.pas with the following code to fix the issue:

  if cg.CellIndex = 0 then
  begin
    i := ARow + 1;
    while (i < RowCount) do
    begin
      if IsNode(i) then Break;
      Inc(i);
    end;
    j := RemapRowInv(i);
    i := RemapRowInv(ARow);
  end
  else
  begin
    i := RemapRowInv(ARow);
    j := i + cg.CellIndex;
  end;

Use of nodes was not designed to be used together with row hiding/unhiding. Node functionality internally uses row hiding/unhiding already and using it from collaps/expand nodes conflicts with separately added hidden rows.

Ok, if this is not a bug, then it is a feature request now. There is a use case, e.g. when you have master records with or without details with a filter on the master records which you can switch on or off, but you won't create a node for those master records without details.

As explained, separate row hiding from hiding rows via collapsing nodes is conflicting.

If you want to filter certain rows, we'd recommend to remove the rows and after this, perform the grouping or adding the nodes.