Chinaunix首页 | 论坛 | 博客
  • 博客访问: 479508
  • 博文数量: 178
  • 博客积分: 2547
  • 博客等级: 少校
  • 技术积分: 1764
  • 用 户 组: 普通用户
  • 注册时间: 2006-02-22 08:27
文章分类

全部博文(178)

文章存档

2014年(2)

2013年(2)

2012年(2)

2010年(19)

2009年(26)

2008年(69)

2007年(20)

2006年(38)

我的朋友

分类: 敏捷开发

2014-06-24 17:09:28

AdvStringGrid的分组功能

procedure Group(ColIndex:integer);

procedure UnGroup;

property GroupColumn:integer;

procedure SubGroup(ColIndex:integer);

 

The Group method is equivalent to assignment of the GroupColumn property, ie :
AdvStringGrid.Group(5) has the same effect as AdvStringGrid.GroupColumn := 5;

 

Note that the column for grouping can only start from column 1, since column 0 is the placeholder for the expand / contract nodes. The GroupColumn property has the additional benefit that it returns -1 when grouping is not active. Otherwise it returns the current grouped column.

 

Example: loading a CSV file, applying grouping and performing a grouped sort
// loading CSV file in normal cells AdvStringGrid1.SaveFixedCells := False;
AdvStringGrid1.LoadFromCSV('cars.csv'); // automatically adapt column width to max. text width in columns
AdvStringGrid1.AutoSizeColumns(False,10); // insert column as placeholder for nodes
AdvStringGrid1.InsertCols(0,1); // setting width of node column to fixed width of 20
AdvStringGrid1.ColWidths[0] := 20;
// do grouping on column 1
AdvStringGrid1.GroupColumn := 1;
// apply grouped sorting on (new) column 1
AdvStringGrid1.SortSettings.Column := 1;
AdvStringGrid1.QSortGroup;

 

When a grouped view is no longer necessary, it can be removed by:
AdvStringGrid.UnGroup;

 

Some extra capabilities for more visually appealing grouping can be set through the property grid.Grouping. Through this property it can be enabled that group headers are automatically set in a different color and that cells from a group header are automatically merged. In addition, a group can also have a summary line. A summary line is an extra row below items that belong to the same group. This summary line can be used to put calculated group values in. The color for this summary line can also be automatically set as well as cell merging performed on this.
Grouping property:

  AdvStringGrid的分组功能

grid.GroupSum(AColumn: Integer);

//Calculates column sums per group
grid.GroupAvg(AColumn: Integer);
//Calculates column averages per group
Grid.GroupMin(AColumn: Integer);
//Calculates column minimum per group
Grid.GroupMax(AColumn: Integer); Calculates column minimum per group
//Grid.GroupCount(AColumn: Integer);
Calculates number of rows in a group for each group Grid.GroupCustomCalc(AColumn: Integer);
//Allows to perform a custom calculation of group data with the event OnGroupCalc

 

If there is a need for a special group calculation that is not available in the standard group calculation functions, the method grid.GroupCustomCalc can be used. For each group in the grid, this will trigger the event grid.OnGroupCalc(Sender: TObject; ACol, FromRow, ToRow: Integer; var Res: Double);

 

In this sample, the grid is initialized with random number, is grouped on column 1 and for the first column in the grouped grid the standard deviation is calculated:
procedure TForm1.AdvStringGrid1GroupCalc(Sender: TObject; ACol, FromRow,
ToRow: Integer; var Res: Double);
var i: integer; d, m, sd: double;
begin // calculate mean m := 0; for i := FromRow to ToRow do begin m := m + advstringgrid1.Floats[ACol,i]; end;
m := m / (ToRow - FromRow + 1);
// calculate standard deviation

sd := 0; for i := FromRow to ToRow do begin sd := sd + sqr(advstringgrid1.Floats[ACol,i] - m); end;
sd := sd / (ToRow - FromRow); Res := sqrt(sd); end;
procedure TForm1.FormCreate(Sender: TObject); var i: integer;
begin

  AdvStringGrid1.RowCount := 100;

  AdvStringGrid1.RandomFill(false,100);

  for i := 1 to AdvStringGrid1.RowCount - 1 do

    AdvStringGrid1.Ints[1,i] := random(5);

  AdvStringGrid1.Grouping.Summary := true;

  AdvStringGrid1.Grouping.MergeHeader := true;

  AdvStringGrid1.Grouping.ShowGroupCount := true;

  Advstringgrid1.Group(1);

  Advstringgrid1.GroupCustomCalc(1);

end;

  AdvStringGrid的分组功能

Subgroups
In this example, a first group is created by calling grid.Group(1). Two additional subgroups are
added by calling grid.SubGroup(1) and grid.SubGroup(2);
The full code used to create this starting from a default grid is:
procedure TForm1.Button1Click(Sender: TObject);
begin
  AdvStringGrid1.RowCount := 100;
  AdvStringGrid1.Randomfill(false,3);
  AdvStringGrid1.Group(1);
  AdvStringGrid1.SubGroup(1);
  AdvStringGrid1.SubGroup(2);
  AdvStringGrid1.ColWidths[1] := 10;
  AdvStringGrid1.ColWidths[2] := 10;
end;


阅读(1411) | 评论(0) | 转发(0) |
0

上一篇:根据DELTA自动生成SQL语句

下一篇:没有了

给主人留下些什么吧!~~