TAdvStringGrid
Example 38 : grouping and merged group headers

procedure TForm1.GroupBtnClick(Sender: TObject); var i: Integer; begin AdvStringGrid1.InsertCols(0,1); // insert a new column to place the grouping nodes in AdvStringGrid1.ColWidths[0] := 20; // make this a small column, just wide enough to fit the node graphic AdvStringGrid1.Group(1); // perform grouping based on column 1 for i := 1 to AdvStringGrid1.RowCount - 1 do begin if AdvStringGrid.IsNode(i) then AdvStringGrid1.MergeCells(1,i,AdvStringGrid1.ColCount,1); // Merge the full row end; end;
Before ungrouping the cell merging is removed again with the SplitCells method:
procedure TForm1.UnGroupBtnClick(Sender: TObject); var i: Integer; begin AdvStringGrid1.ExpandAll; for i := 1 to AdvStringGrid1.RowCount - 1 do begin if AdvStringGrid.IsNode(i) then AdvStringGrid1.SplitCells(1,i); // split cells again end; AdvStringGrid1.UnGroup; AdvStringGrid1.RemoveCols(0,1); // remove the place holder column for group nodes again end;
Delphi project & source files for downloading included in the main demos distribution for Delphi.
×