惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
S
Securelist
MyScale Blog
MyScale Blog
Jina AI
Jina AI
罗磊的独立博客
The Cloudflare Blog
美团技术团队
博客园 - 叶小钗
阮一峰的网络日志
阮一峰的网络日志
博客园 - 三生石上(FineUI控件)
月光博客
月光博客
雷峰网
雷峰网
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
大猫的无限游戏
大猫的无限游戏
博客园 - Franky
博客园 - 聂微东
Y
Y Combinator Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
MongoDB | Blog
MongoDB | Blog
T
Tailwind CSS Blog
Attack and Defense Labs
Attack and Defense Labs
博客园_首页
Latest news
Latest news
Apple Machine Learning Research
Apple Machine Learning Research
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Hacker News
The Hacker News
G
GRAHAM CLULEY
Simon Willison's Weblog
Simon Willison's Weblog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
U
Unit 42
D
Docker
Webroot Blog
Webroot Blog
N
Netflix TechBlog - Medium
T
Tor Project blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LINUX DO - 最新话题
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Last Watchdog
The Last Watchdog
B
Blog
Recent Announcements
Recent Announcements
GbyAI
GbyAI
Microsoft Azure Blog
Microsoft Azure Blog
Security Latest
Security Latest
V2EX - 技术
V2EX - 技术
N
News | PayPal Newsroom
Microsoft Security Blog
Microsoft Security Blog

博客园 - 方子

2026 新年寄语:深耕数字转型,共筑时尚未来 加入博客园会员 在自己订阅的GOOGLE快讯中,看到自己的文章 想法: PDA中几个常用数据取得方法 HOWTO:如何分别把每个用户的自定义模型数据保存到数据库 域名被停  郁闷 中.... 建立了一个Symbol PDA WM 相关技术的QQ讨论群,欢迎大家参加。 下载了一个Writer+Source Code Plug In 写Blog 【转载】C#输入汉字字符串索引拼音的首字母 [转载]RAID0、RAID1、RAID0+1、RAID5原理介绍 如何做好一个销售人员 开始→运行→输入的命令集锦 ERP真正能给企业带来什么 Symbol MC1000 vs2005 开发中的一些问题. 常用条码打印机测纸方法 Symbol MC1000 开发 几个 IDE 插件列表如下 VB.net改为C#
HOWTO:XAF中如何自定义导出动作.
方子 · 2010-11-05 · via 博客园 - 方子

英文原文地址:http://documentation.devexpress.com/#Xaf/CustomDocument3287

The default List Editor in Windows Forms XAF applications is the XtraGrid control. This control has an option to export its content to various formats. In XAF applications, the export functionality is provided via the Export Action. This Action is presented by the abstract ExportController View Controller, which is the base for the XtraGridExportController Controller. The XtraGridExportController Controller is activated for all List Views. Its Export action is active when the current List Editor control is XtraGrid.

XAF程序中默认的列表编辑是XtraGrid,XtraGrid有一个可以导出多种文件格式的选项,在XAF程序中,导出功能是通过 Export 动作来实现,此动作由继承于VewController的ExportController来提供,EportController也是XtraGridExportController的父类,XtraGridExportGrid在所有的列表中均有效, 当列表编辑器是XtraGrid时.Export动作是可用的.

This topic describes how to access the XtraGridExportController and customize the Export Action behavior via the controller's events:

本文详细指出如何取得XtraGridExportController ,并如何通过控制器的如下事件自定义Export 动作的相关行为.

ExportController.CustomExport
ExportController.Exported

Customizing the Export Action via the CustomExport Event

通过 CustomExport 事件自定义 Export  动作.

The CustomExport event occurs before export, after a user specifies the target file name in the Save as dialog. The handler's FileName and Stream parameters provide you with access to the target file name and System.IO.Stream object, representing data to be exported. You can handle this event, to adjust objects being exported or to manually perform the export operation (set the handler's Handled parameter to true, in this case). In this example, we will handle this event to notify an end-user when the exporting List View has collapsed groups, and provide him with the ability to choose whether to expand them in the exported file. This will override the default behavior when the collapsed groups are always expanded in the exported file.

事件:CustomExport 发生在导出动作之前,用户指定另存为对话框中的文件名后.通过参数:FileNameStream 可以取得导出对象的文件名和表示导出数据的流对象:System.IO.Stream .通过调用本事件,你可以判断对象在导出后是否存在做一些导出选项的手工动作(在本实例中.设置handler 的 Handled 参数为True).在这个示例中,我们通过调用本事件,在最终用户收缩起列表导出的时候,发出提醒,并让最终用户选择是否导出收缩的表格.这会覆盖默认的行为.

To detect if there are collapsed groups, we need to iterate through the grid's group rows. The group rows have negative handles in the Grid View (see Process Group Rows). The expansion status of a group row can be determined by the GridView.GetRowExpanded method. We will display the message box when the collapsed group is detected, and set the GridOptionsPrint.ExpandAllGroups property, according to the user's selection. The following View Controller implements the required behavior:

判断列表是否收缩起列表,通过表格的GROUP ROWS.......

代码

using System.Windows.Forms;
using DevExpress.ExpressApp.Win;
using DevExpress.ExpressApp.Win.Editors;
using DevExpress.ExpressApp.SystemModule;
using DevExpress.ExpressApp.Win.SystemModule;
// ... 
public partial class CustomizeXtraGridExportController : ViewController
{
    
public CustomizeXtraGridExportController() {
        InitializeComponent();
        RegisterActions(components);
    }
    
private XtraGridExportController exportController;
    
protected override void OnActivated() {
        
base.OnActivated();
        exportController 
= Frame.GetController<XtraGridExportController>();
        exportController.CustomExport 
+= exportController_CustomExport;
    }
    
void exportController_CustomExport(object sender, CustomExportEventArgs e) {
        GridListEditor gridListEditor 
= 
            ((DevExpress.ExpressApp.ListView)View).Editor 
as GridListEditor;
        XafGridView gridView 
= gridListEditor.GridView;
        
if (HasCollapsedGroups(gridView)) {
            
if (WinApplication.Messaging.GetUserChoice(
                
"There are collapsed groups in the grid. Expand all groups in the exported file?",
                
"Export", MessageBoxButtons.YesNo) == DialogResult.Yes)
                gridView.OptionsPrint.ExpandAllGroups 
= true;
            
else gridView.OptionsPrint.ExpandAllGroups = false;
        }
    }
    
private bool HasCollapsedGroups(XafGridView gridView) {
        
if (gridView.GroupCount > 0) {
            
int rowHandle = -1;
            
while (gridView.IsValidRowHandle(rowHandle)) {
                
if (!gridView.GetRowExpanded(rowHandle)) return true;
                rowHandle
--;
            }
        }
        
return false;
    }
    
protected override void OnDeactivating() {
        
base.OnDeactivating();
        exportController.CustomExport 
-= exportController_CustomExport;
    }
}

 <注>以上代码通过在PROJECT.MODULE.WIN中新增一个:ViewController类.

End-users will see the following message box when exporting a List View containing collapsed groups:

最终用户在收缩列表导出时会看到下列对话框.

If the choice is "Yes", all the grid's rows will be exported.

如果选择"是",则表格行会被导出.

If the choice is "No", the rows belonging to the collapsed groups won't be included in exported file.

如果选择则"否",则被收缩的行不会在导出的文件中.

Customizing the Export Action via the Exported Event

通过Exported 事件自定义导出动作

The Exported event occurs after an export operation has been completed. The handler's FileName and Stream parameters provide you with access to the target file name and System.IO.Stream object, representing export data. You can handle this event to perform custom post-export actions. In this example, we will provide the end-user with the ability to open the exported file immediately. The following View Controller implements the required behavior.

Exported 事件产生在导出操作完成之后.参数FileNameStream 可以取得导出文件的名称和文件流对象(System.IO.Stream).你可以在导出动作完成后加入你想要的动作.

代码

using System.IO;
using System.Windows.Forms;
using DevExpress.ExpressApp.Win;
using DevExpress.ExpressApp.SystemModule;
using DevExpress.ExpressApp.Win.SystemModule;
// ... 
public partial class CustomizeXtraGridExportController : ViewController
{
    
public CustomizeXtraGridExportController() {
        InitializeComponent();
        RegisterActions(components);
    }
    
private XtraGridExportController exportController;
    
protected override void OnActivated() {
        
base.OnActivated();
        exportController 
= Frame.GetController<XtraGridExportController>();
        exportController.Exported 
+= exportController_Exported;
    }
    
void exportController_Exported(object sender, CustomExportEventArgs e) {
        
if (File.Exists(e.FileName)) {
            
if (WinApplication.Messaging.GetUserChoice("Open exported file?",
                
"Export", MessageBoxButtons.YesNo) == DialogResult.Yes)
                Process.Start(e.FileName);
        }
    }
    
protected override void OnDeactivating()
    {
        
base.OnDeactivating();
        exportController.Exported 
-= exportController_Exported;
    }
}

The following image illustrates the message box shown after the export has been finished.

导出完成后将显示下列的对话框.