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?