1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
procedure CreateMultiBands(GridView:TcxGridDBBandedTableView;cds:TClientDataSet);
var
band,band1:TcxGridBand;
col:TcxGridDBBandedColumn;
fieldCount:Integer;
i,j,k:Integer;
Lines:TStringList;
bandCaption:string;
bands:TDictionary<string,TcxGridBand> ;
begin
bands := TDictionary<string, TcxGridBand>.Create;
fieldCount := cds.Fields.Count;
GridView.BeginUpdate(lsimPending);
for i := 0 to fieldCount - 1 do
begin //第一层表头绘制
Lines := TStringList.Create;
ExtractStrings(['|'], [], PChar(cds.Fields[i].FieldName), Lines); //对一个字段进行分割处理
bandCaption := '';
if not bands.ContainsKey(Lines[0] + '|') then //如果第一行重复不添加
begin
band := GridView.Bands.Add;
band.Caption := Lines[0];
bandCaption := Lines[0] + '|';
if Lines.Count = 1 then
begin
col := GridView.CreateColumn;
col.Position.BandIndex := band.Index;
col.DataBinding.FieldName := cds.Fields[i].FieldName;
end;
bands.Add(bandCaption, band);
end;
FreeAndNil(Lines);
end;
for i := 0 to fieldCount - 1 do
begin
Lines := TStringList.Create;
ExtractStrings(['|'], [], PChar(cds.Fields[i].FieldName), Lines);
for j := 1 to Lines.Count - 1 do
begin
band := GridView.Bands.Add;
band.Caption := Lines[j];
bandCaption := '';
for k := 0 to j - 1 do
begin
bandCaption := bandCaption + Lines[k] + '|';
end;
if bands.TryGetValue(bandCaption, band1) then
begin
band.Position.BandIndex := band1.Position.Band.Index;
end;
bandCaption := '';
for k := 0 to j do
begin
bandCaption := bandCaption + Lines[k] + '|';
end;
if Lines.Count - 1 = j then
begin
col := GridView.CreateColumn;
col.Position.BandIndex := band.Index;
col.DataBinding.FieldName := cds.Fields[i].FieldName;
;
end;
bands.Add(bandCaption, band);
end;
FreeAndNil(Lines);
end;
GridView.EndUpdate;
end;
|