TTMSFNCDataGrid and grouping-ordering

First of all, I started to use the new DataGrid and I find it excellent.
I see something I can not understand when grouping. See the following source:

unit Unit2;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, VCL.TMSFNCTypes, VCL.TMSFNCUtils,
  VCL.TMSFNCGraphics, VCL.TMSFNCGraphicsTypes, System.Rtti,
  VCL.TMSFNCDataGridCell, VCL.TMSFNCDataGridData, VCL.TMSFNCDataGridBase,
  VCL.TMSFNCDataGridCore, VCL.TMSFNCDataGridRenderer, Vcl.StdCtrls,
  VCL.TMSFNCCustomControl, VCL.TMSFNCDataGrid;

type
  TForm2 = class(TForm)
    tabl: TTMSFNCDataGrid;
    b_hide: TButton;
    b_unhide: TButton;
    b_group: TButton;
    b_ungroup: TButton;
    i_col: TEdit;
    i_row: TEdit;
    procedure FormCreate(Sender: TObject);
    procedure b_hideClick(Sender: TObject);
    procedure b_unhideClick(Sender: TObject);
    procedure b_groupClick(Sender: TObject);
    procedure b_ungroupClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.FormCreate(Sender: TObject);  
var n:integer;
begin 
tabl.ColumnCount:=8; tabl.RowCount:=200; 
tabl.FixedRowCount:=1; tabl.FixedColumnCount:=1; 
tabl.LinearFill(true);
for n:=1 to tabl.RowCount-1 do begin
tabl.Cells[0,n]:=(n div 10)+1;
tabl.Cells[1,n]:=n;
end;
tabl.Options.Grouping.MergeHeader:=true;
tabl.Options.Grouping.Summary:=false;
tabl.Options.Grouping.HideColumns:=true;
end;

procedure TForm2.b_hideClick(Sender: TObject);
var i:integer;
begin 
i:=strtointdef(i_col.Text,-1); if i>=0 then tabl.HideColumn(i);
i:=strtointdef(i_row.Text,-1); if i>=0 then tabl.HideRow(i);
end;

procedure TForm2.b_unhideClick(Sender: TObject);
var i:integer;
begin 
i:=strtointdef(i_col.Text,-1); if i>=0 then tabl.unHideColumn(i);
i:=strtointdef(i_row.Text,-1); if i>=0 then tabl.unHideRow(i);
end;

procedure TForm2.b_groupClick(Sender: TObject);
begin tabl.group(0); end;

procedure TForm2.b_ungroupClick(Sender: TObject);
begin tabl.ungroup; end;

end.

Without grouping everything seems OK. I can hide and unhide every column and row using the number that it is shown by LinearFill.
If I group them, then I am getting the following image where the initial ordering is changed and at the same time, when ungrouping them back, they stay with the same ordering.

Trying to hide/unhide rows after being grouped, the row numbers are not connected with the numbers in the cells created by LinearFill, they seem to be the visible cell place (including the group MergeHeader as you can see in the following image, where the row 19 is the row with 12 in first column:

I tried to change the group command to the following (having in mind to create a sort column that will be hidden):

procedure TForm2.b_groupClick(Sender: TObject);
begin tabl.group([0],[0,1]); end;

Now the view seems OK, but when I try to hide a row, again the Mergedheaders are included in counting as you can see in the image:

I changed the hiding function as the following:

procedure TForm2.b_hideClick(Sender: TObject);
var i:integer;  a:TTMSFNCDataGridCellCoord;
begin 
i:=strtointdef(i_col.Text,-1); 
if i>=0 then tabl.HideColumn(i);
i:=strtointdef(i_row.Text,-1);
if i>=0 then begin
  a.Column:=1; a.Row:=i;
  a:=tabl.DisplayToRealCell(a);
  tabl.HideRow(a.Row); 
end;
end;

But this does not also seem to work OK: Requesting to hide the row 21, removes the row with 2:17


Can you please help me to understand how to deal with such cases?

I am using version 0.9.0.3

You are actually using the reverse method, DisplayToRealCell is using the index of the displayed cells and converts it to the real cell. What you actually want is the Real Cell (original cell position and number) and convert it to the Display position. All actions in the grid are based on the displayed row & column, not the real indexes.

Unfortunately while testing this I noticed the RealToDisplayCell is not returning the value internally, so this specific function will require a source patch. What you can use as an alternative is the Column & Row Order:

tabl.HideRow(tabl.RowOrders[i]);

Or you can also directly access the function with

tabl.Root.RealToDisplayCell();

while awaiting the source patch

Thank you very much, it works OK now.

Some glitches I noticed in designing:

  1. in form designing, if you close the left panel with "Load sample","Filtering",etc the control gets smaller, even if all anchors are selected
  2. If you add TTMSFNCDataGridxxxx (Excel,Print,PDF) in the form with the DataGrid selected, they are children of the DataGrid in the screen and the next time you load the .frm file they are lost

Hi,

  1. The designer panel is actually part of the grid, when hiding it, the Width is decreased to avoid having a grid that's too wide.
  2. This is because they are actually real visual controls, but developed as non-visual components. This technique is required because we can register these controls twice, once for VCL & once for FMX. Visual Controls can indeed be dropped as a child of the grid. We'll investigate if we can implement a technique to avoid this.