使用Winforms Devexpress的XtraReports C#.Net中的报表查看器? [英] Report viewer in XtraReports C#.Net using Winforms Devexpress?

查看:89
本文介绍了使用Winforms Devexpress的XtraReports C#.Net中的报表查看器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我使用XtraReports创建了三个报告.我可以使用此代码在按钮点击中查看该内容

Hi I created three reports using XtraReports. I can able to view that in button click using this code

 xtrareport1 report = new xtrareport1 (Convert.ToInt32(TXE_CompanyId.Text));
 ReportPrintTool tool = new ReportPrintTool(report);
 tool.ShowPreview();

我需要在LookupEdit中显示这三个报告名称,并且用户选择一个报告意味着需要在PrintControl1中显示该预览?该怎么做?

I need to show this three reports name in LookupEdit and user select a report means need to show that preview in PrintControl1 ? How to do this ?

推荐答案

如果要在项目中获取所有报告,则可以使用

If you want to get all reports in your project then you can use the solution provided by DevExpress:

您可以使用Assembly.GetExecutingAssembly().GetTypes()方法来获取程序集中定义的所有类.然后你可以循环查找从XtraReport类派生的类的列表.去创造一个新实例,请使用Activator.CreateInstance()方法.

You can use the Assembly.GetExecutingAssembly().GetTypes() method to get all classes defined in the assembly. Then you can cycle through the list to find classes derived from the XtraReport class. To create a new instance, use the Activator.CreateInstance() method.

以下是实现示例:

public Form1()
{
    InitializeComponent();

    var reports = new List<Tuple<string, Type>>();

    foreach (var type in Assembly.GetExecutingAssembly().GetTypes())
        if (type.IsSubclassOf(typeof(XtraReport)))
            reports.Add(new Tuple<string, Type>(type.Name, type));

    lookUpEdit1.Properties.DataSource = reports;
    lookUpEdit1.Properties.DisplayMember = "Item1";
    lookUpEdit1.Properties.ValueMember = "Item2";
    lookUpEdit1.Properties.Columns.Add(new LookUpColumnInfo("Item1","Report"));
}

private void simpleButton1_Click(object sender, EventArgs e)
{
    var value = lookUpEdit1.EditValue;

    if (value == null)
        return;

    var report = (XtraReport)Activator.CreateInstance((Type)value);

    var tool = new ReportPrintTool(report);
    tool.ShowPreview();
}

这篇关于使用Winforms Devexpress的XtraReports C#.Net中的报表查看器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆