-
Notifications
You must be signed in to change notification settings - Fork 1
/
WispViewTools.pas
88 lines (74 loc) · 2.22 KB
/
WispViewTools.pas
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
unit WispViewTools;
interface
uses
CxGrid,
CxGridLevel,
CxGridTableView,
CxGridDbTableView;
function GetColumnIndexFromColumnCaption(ParamView: TcxGridDBTableView;
ParamColumnCaption: String): Integer; overload;
function GetColumnIndexFromColumnCaption(ParamView: TcxGridTableView;
ParamColumnCaption: String): Integer; overload;
Procedure MaximizeColumnWidth(ParamView: TcxGridDBTableView;
ParamWidth: Integer);
implementation
// =============================================================================
// Get the column index from the caption of a column
function GetColumnIndexFromColumnCaption(ParamView: TcxGridDBTableView;
ParamColumnCaption: String): Integer;
var
I: Integer;
begin
for I := 0 to ParamView.ColumnCount - 1 do
begin
if ParamView.Columns[I].Caption = ParamColumnCaption then
begin
result := I;
EXIT;
end;
end;
end;
// =============================================================================
// Get the column index from the caption of a column
function GetColumnIndexFromColumnCaption(ParamView: TcxGridTableView;
ParamColumnCaption: String): Integer;
var
I: Integer;
begin
for I := 0 to ParamView.ColumnCount - 1 do
begin
if ParamView.Columns[I].Caption = ParamColumnCaption then
begin
result := I;
EXIT;
end;
end;
end;
// =============================================================================
// ...
Procedure MaximizeColumnWidth(ParamView: TcxGridDBTableView;
ParamWidth: Integer);
var
I, Width, ColumnsWidth: Integer;
ScalingValue, TmpR: Real;
begin
// Width := (ParamView.Control as TcxGrid);
Width := ParamWidth;
ColumnsWidth := 0;
for I := 0 to ParamView.ColumnCount - 1 do
begin
if ParamView.Columns[I].Visible = TRUE then
ColumnsWidth := ColumnsWidth + ParamView.Columns[I].Width;
end;
if ColumnsWidth < Width then
begin
ScalingValue := Width / ColumnsWidth;
for I := 0 to ParamView.ColumnCount - 1 do
begin
if ParamView.Columns[I].Visible = TRUE then
TmpR := ParamView.Columns[I].Width * ScalingValue;
ParamView.Columns[I].Width := Round(TmpR);
end;
end;
end;
end.