FMenuItem := TMenuItem.Create(Self); FMenuItem.Name := 'miCustomFilter'; FMenuItem.Caption := '自定义过滤(&M)'; FMenuItem.OnClick := miCustomFilterClick; TPopupMenu(AMenu).Items.Add(FMenuItem);
//过滤管理器
FMenuItem := TMenuItem.Create(Self); FMenuItem.Name := 'miFilterBuilder';
TPopupMenu(AMenu).Images.AddImage(FormMain.ImageListExtend, 44); //添加图标图像 FMenuItem.ImageIndex := TPopupMenu(AMenu).Images.Count - 1; //指定图标序号 FMenuItem.Caption := '过滤管理器';
FMenuItem.OnClick := Self.miFilterBuilderClick; TPopupMenu(AMenu).Items.Add(FMenuItem);
//---------------------
FMenuItem := TMenuItem.Create(Self); FMenuItem.Caption := '-';
TPopupMenu(AMenu).Items.Add(FMenuItem);
//导出
FMenuItem := TMenuItem.Create(Self); FMenuItem.Name := 'miExport';
TPopupMenu(AMenu).Images.AddImage(FormMain.ImageListExtend, 37); FMenuItem.ImageIndex := TPopupMenu(AMenu).Images.Count - 1; FMenuItem.Caption := '导出(&E)';
FMenuItem.OnClick := Self.miExportClick; TPopupMenu(AMenu).Items.Add(FMenuItem);
//打印
FMenuItem := TMenuItem.Create(Self); FMenuItem.Name := 'miPrint';
FMenuItem.Caption := '打印(&P)';
TPopupMenu(AMenu).Images.AddImage(FormMain.ImageListExtend, 14); FMenuItem.ImageIndex := TPopupMenu(AMenu).Images.Count - 1; FMenuItem.OnClick := Self.miPrintClick; TPopupMenu(AMenu).Items.Add(FMenuItem); end; end;
procedure TFormItemList.miExportClick(Sender: TObject); var
FileName, FileExt, msg: String; begin
if Self.aqyQuery.IsEmpty then
begin
msg := '没有导出数据...';
Application.MessageBox(PChar(msg), PChar(Application.Title), MB_OK or MB_IconWarning); Exit; end;
Self.SaveDialogExport.Filter := 'Excel文件 (*.xls)|*.xls|XML文件 (*.xml)|*.xml' + '|文本文件 (*.txt)|*.txt|网页文件 (*.html)|*.html'; Self.SaveDialogExport.Title := '导出为';
if not Self.SaveDialogExport.Execute then Exit;
FileName := Self.SaveDialogExport.FileName; FileExt := LowerCase(ExtractFileExt(FileName)); if FileExt = '.xls' then
ExportGrid4ToExcel(FileName, Self.cxGrid1) else if FileExt = '.xml' then
ExportGrid4ToXML(FileName, Self.cxGrid1) else if FileExt = '.txt' then
ExportGrid4ToText(FileName, Self.cxGrid1) else if FileExt = '.html' then
ExportGrid4ToHTML(FileName, Self.cxGrid1) else begin
msg := '不支持的导出文件类型...';
Application.MessageBox(PChar(msg), PChar(Application.Title), MB_OK or MB_IconError); Exit; end;
msg := '导出完成...';
Application.MessageBox(PChar(msg), PChar(Application.Title), MB_OK or MB_IconInformation); end;
procedure TFormItemList.miPrintClick(Sender: TObject); begin //打印
Self.dxComponentPrinter.Preview(True, Self.dxComponentPrinterLink1); end;
procedure TFormItemList.cxGridPopupMenuPopup(ASenderMenu: TComponent;
AHitTest: TcxCustomGridHitTest; X, Y: Integer; var AllowPopup: Boolean); begin
if GetHitTypeByHitCode(AHitTest.HitTestCode) = gvhtColumnHeader then //右击列标题时 begin
//if tvResult.DataController.Groups.GroupingItemCount > 0 then if tvResult.GroupedColumnCount > 0 then //有分组时显示 begin
TMenuItem(Self.FindComponent('miLineForGroup')).Visible := True; TMenuItem(Self.FindComponent('miExpandAllGroup')).Visible := True; TMenuItem(Self.FindComponent('miCollapseAllGroup')).Visible := True; end else begin
TMenuItem(Self.FindComponent('miLineForGroup')).Visible := False; TMenuItem(Self.FindComponent('miExpandAllGroup')).Visible := False; TMenuItem(Self.FindComponent('miCollapseAllGroup')).Visible := False; end; end; end;
procedure TFormItemList.miFilterBuilderClick(Sender: TObject); begin
//过滤管理器
//弹出Filter Builder Dialog对话框 tvResult.Filtering.RunCustomizeDialog; end;
procedure TFormItemList.miCustomFilterClick(Sender: TObject); var
AHitTest: TcxCustomGridHitTest; begin
//自定义过滤
//弹出Custom Filter Dialog对话框
AHitTest := cxGridPopupMenu.HitTest;
if GetHitTypeByHitCode(AHitTest.HitTestCode) = gvhtColumnHeader then //获得右击的列 tvResult.Filtering.RunCustomizeDialog(TcxGridColumnHeaderHitTest(AHitTest).Column); end;
procedure TFormItemList.miFilterPanelClick(Sender: TObject); var
mi: TMenuItem; begin
//隐藏/显示过滤面板
mi := TMenuItem(Sender);
mi.Checked := True;
if mi.Name = 'miFilterPanelAlways' then tvResult.Filtering.Visible := fvAlways
else if mi.Name = 'miFilterPanelNerver' then tvResult.Filtering.Visible := fvNever else
tvResult.Filtering.Visible := fvNonEmpty; end;
procedure TFormItemList.miExpandAllGroupClick(Sender: TObject); begin
//展开所有组
tvResult.DataController.Groups.FullExpand; end;
procedure TFormItemList.miCollapseAllGroupClick(Sender: TObject); begin
//收缩所有组
tvResult.DataController.Groups.FullCollapse; end;
此楼回复Re:
在用,留名
此楼回复Re:
技巧三 按条件计算合计值
在Footer的第一列显示[合计:]
加一个Summary项,Column设为Grid的第一列,Kind设为skNone 在该Summary项的OnGetText事件中,输入:
procedure TFormExpense.tvExpenseTcxGridDBDataControllerTcxDataSummaryFooterSummaryItems2GetText(
Sender: TcxDataSummaryItem; const AValue: Variant; AIsFooter: Boolean; var AText: String); begin
AText := '合计:'; end;
按条件汇总:
在TableView的DataController->Summary->FooterSummary->OnSummary事件中,输入:
相关推荐: