📄 ufrmshowcxgrdrow.pas
字号:
unit uFrmShowCxGrdRow;
interface
uses
Windows, Messages, Sysutils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls, Buttons, ComCtrls, CheckLst, RzButton, cxGridTableView, cxGridDBTableView, cxGrid;
type
TFrmShowCxGrdRow = class(TForm)
ChkLstBox: TCheckListBox;
BtnOk: TRzBitBtn;
BtnCancel: TRzBitBtn;
chkSelectALL: TCheckBox;
procedure BtnCancelClick(Sender: TObject);
procedure BtnOkClick(Sender: TObject);
procedure chkSelectALLClick(Sender: TObject);
private
{ Private declarations }
procedure SetChecked(bCheck: Boolean);
public
end;
procedure SetShowCxgrdRow(aTempgrd: TcxGridDBTableView);
implementation
{$R *.DFM}
procedure SetShowCxgrdRow(aTempgrd: TcxGridDBTableView);
var
I, CheckIndex: Integer;
FrmShowCxGrdRow: TFrmShowCxGrdRow;
begin
if not aTempGrd.DataController.DataSource.DataSet.Active then
Exit;
if aTempGrd.ColumnCount = 0 then Exit;
FrmShowCxGrdRow := TFrmShowCxGrdRow.Create(Application);
with FrmShowCxGrdRow, aTempgrd do
try
for i := 0 to aTempgrd.ColumnCount - 1 do {初始 ChkLstBox}
begin
CheckIndex := ChkLstBox.Items.Add(Columns[i].Caption + '(' + Columns[i].DataBinding.FieldName + ')');
ChkLstBox.Checked[CheckIndex] := Columns[i].Visible;
end;
{返回 GrdRow}
if ShowModal = mrOK then
for i := 0 to ChkLstBox.Count - 1 do
Columns[i].Visible := ChkLstBox.Checked[i]
finally
FrmShowCxGrdRow.Free;
end;
end;
{设置 取消 / 选择}
procedure TFrmShowCxGrdRow.SetChecked(bCheck: Boolean);
var
i: Integer;
begin
for i := 0 to ChkLstBox.Items.Count - 1 do
ChkLstBox.Checked[i] := bCheck;
end;
procedure TFrmShowCxGrdRow.BtnCancelClick(Sender: TObject);
begin
ModalResult := mrCancel;
end;
{提交}
procedure TFrmShowCxGrdRow.BtnOkClick(Sender: TObject);
var
I, J: integer;
begin
J := 0;
for i := 0 to ChkLstBox.Items.Count - 1 do
if ChkLstBox.Checked[i] then
begin
INC(J);
Break;
end;
if J = 0 then
begin
Application.MessageBox('最少要选择一个显示项目', '操作提示', MB_OK + mb_IconInformation);
if ChkLstBox.CanFocus then
ChkLstBox.setfocus;
Exit;
end;
ModalResult := mrOk;
end;
{全选 , 清空}
procedure TFrmShowCxGrdRow.chkSelectALLClick(Sender: TObject);
begin
SetChecked(chkSelectALL.Checked);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -