-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDBGrid_custom.pas
More file actions
167 lines (132 loc) · 4.6 KB
/
Copy pathDBGrid_custom.pas
File metadata and controls
167 lines (132 loc) · 4.6 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
{ -----------------------------------------------------------------------------
Author: Messias Antonio Natal
Date: 23-Fevereiro-2020
Description: Componente para gestão de colunas do BDGrid - FREE
----------------------------------------------------------------------------- }
{ ******************************************************************************
|* Historico
|*
|* 23/02/2020: Messias Antonio Natal
|* - Criação e distribuição da Primeira Versão
*******************************************************************************}
unit DBGrid_custom;
interface
uses
System.SysUtils, Vcl.ActnList, Vcl.Dialogs, System.Classes,
Vcl.Forms, Vcl.DBGrids,Vcl.CheckLst,Vcl.Controls, Vcl.Buttons,
DBGrid_custom_connectionFD,DBGrid_custom_table;
procedure register;
type
TDBGrid_custom = class(TComponent)
private
FDBGrid_custom_Connection: TDBGrid_custom_connectionFD;
FDBGrid : TDBGrid;
public
constructor Create; virtual;
destructor Destroy; override;
procedure save(pForm: TForm);
procedure load(pForm: TForm);
procedure reset(pForm: TForm);
procedure showFormColumns;
private
function getColumns(pCheckListBox: TCheckListBox): TCheckListBox;
procedure setColumns(pCheckListBox: TCheckListBox);
published
property DBGrid_custom_Connection : TDBGrid_custom_connectionFD read FDBGrid_custom_Connection write FDBGrid_custom_Connection;
property DBGrid : TDBGrid read FDBGrid write FDBGrid;
end;
implementation
{ TDBGrid_custom }
procedure register;
begin
RegisterComponents('DBGrid_custom', [TDBGrid_custom,TDBGrid_custom_connectionFD,TDBGrid_custom_table]);
end;
constructor TDBGrid_custom.Create;
begin
end;
destructor TDBGrid_custom.Destroy;
begin
inherited;
end;
function TDBGrid_custom.getColumns(pCheckListBox: TCheckListBox):TCheckListBox;
var
i : integer;
begin
pCheckListBox.Items.Clear;
for I := 0 to DBGrid.Columns.Count - 1 do
begin
pCheckListBox.AddItem( DBGrid.Columns[i].Title.Caption , DBGrid);
if DBGrid.Columns[i].Width = -1 then
pCheckListBox.Checked[i] := False
else
pCheckListBox.Checked[i] := True;
end;
result := pCheckListBox;
end;
procedure TDBGrid_custom.setColumns(pCheckListBox: TCheckListBox);
var
i: integer;
begin
for i := 0 to DBGrid.Columns.Count - 1 do
begin
if DBGrid.Columns[i].Title.Caption = pCheckListBox.Items[i] then
DBGrid.Columns[i].Visible := pCheckListBox.Checked[i];
end;
end;
procedure TDBGrid_custom.showFormColumns;
var
FormVisibilidadesColunas : TForm;
CheckList : TCheckListBox;
BtnAplicar: TBitBtn;
begin
FormVisibilidadesColunas := TForm.Create(Application);
CheckList := TCheckListBox.Create(Application);
BtnAplicar:= TBitBtn.Create(Application);
try
FormVisibilidadesColunas.Width := 200;
FormVisibilidadesColunas.Height := DBGrid_custom_Connection.getDBGRID.Height;
FormVisibilidadesColunas.Align := alNone;
FormVisibilidadesColunas.BorderStyle := bsSizeToolWin;
FormVisibilidadesColunas.AutoSize := false;
FormVisibilidadesColunas.Visible := false;
FormVisibilidadesColunas.WindowState := wsNormal;
FormVisibilidadesColunas.Position := poScreenCenter;
FormVisibilidadesColunas.Caption := 'Visibilidade das Colunas';
CheckList.Align := alClient;
CheckList.Parent := FormVisibilidadesColunas;
CheckList.Flat := True;
BtnAplicar.AlignWithMargins := True;
BtnAplicar.Kind := bkOK;
BtnAplicar.Height := 27;
BtnAplicar.Align := alBottom;
BtnAplicar.Caption := 'Aplicar';
BtnAplicar.Parent := FormVisibilidadesColunas;
self.getColumns(CheckList);
FormVisibilidadesColunas.ShowModal;
if FormVisibilidadesColunas.ModalResult = mrOk then
begin
self.setColumns(CheckList);
end;
finally
FreeAndNil(BtnAplicar);
FreeAndNil(CheckList);
FreeAndNil(FormVisibilidadesColunas);
end;
end;
procedure TDBGrid_custom.load(pForm: TForm);
begin
DBGrid_custom_Connection.setDBGRID(DBGrid);
DBGrid_custom_Connection.loadTable;
DBGrid_custom_Connection.loadConfig(pForm);
end;
procedure TDBGrid_custom.reset(pForm: TForm);
begin
DBGrid_custom_Connection.setDBGRID(DBGrid);
DBGrid_custom_Connection.reset(pForm);
end;
procedure TDBGrid_custom.save(pForm: TForm);
begin
DBGrid_custom_Connection.setDBGRID(DBGrid);
DBGrid_custom_Connection.save(pForm);
end;
end.