Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#-在运行时更新Crystal报表_C#_.net_Crystal Reports - Fatal编程技术网

C#-在运行时更新Crystal报表

C#-在运行时更新Crystal报表,c#,.net,crystal-reports,C#,.net,Crystal Reports,我试图解决这个问题,但还是没有成功 我在Win 8.1 VS2013社区工作 我有一个带有DatagridView和按钮的简单Winform应用程序。Datagridview有一列,在表单的构造函数中填充示例值 private List<StringValue> list; private List<Report> lr; public Form1() { InitializeComponent();

我试图解决这个问题,但还是没有成功

我在Win 8.1 VS2013社区工作

我有一个带有DatagridView和按钮的简单Winform应用程序。Datagridview有一列,在表单的构造函数中填充示例值

        private List<StringValue> list;
    private List<Report> lr;
    public Form1()
    {
        InitializeComponent();
        list = new List<StringValue>();
        lr = new List<Report>(); 
        list.Add(new StringValue("bla1"));
        list.Add(new StringValue("bla2"));
        dataGridView1.DataSource = list;
    }
报告课是

public class Report
{
    private  string m_name = null;
    private CrystalDecisions.CrystalReports.Engine.ReportDocument m_document;
    public string Name 
    { 
        get{return m_name;}
        set{m_name = value;}
    }
    public ReportDocument reportDocument 
    {
        get { return m_document; }
        set { m_document = value; }
    }

    public Report(string name, ReportDocument doc)
    {
        m_name = name;
        m_document = doc;
    }
}
我还使用listBox创建了其他表单,其中显示了报表和crystalreportviewer控件的名称。单击列表框中的项目后,我想打开从form1发送的crystalreport。以下是源代码:

List<Report> lr = null;
    public ReportViewer()
    {
        InitializeComponent();
    }

    public ReportViewer(List<Report> reports) : this()
    {
        lr = reports;
        foreach (Report report in reports)
        {
            listBox1.Items.Add(report.Name);
        }
        listBox1.SelectedIndex = 0;
    }

    private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        crView.ReportSource = null;
        ReportDocument rep = new ReportDocument();
        rep = GetReport(listBox1.SelectedIndex);
        crView.ReportSource = rep;
        this.crView.RefreshReport();

    }

    private ReportDocument GetReport(int p)
    {
        return lr[p].reportDocument;
    }
}
List lr=null;
公共报告查看器()
{
初始化组件();
}
公共报表查看器(列表报表):this()
{
lr=报告;
foreach(报表中的报表)
{
listBox1.Items.Add(report.Name);
}
listBox1.SelectedIndex=0;
}
私有无效列表框1\u SelectedIndexChanged(对象发送方,事件参数e)
{
crView.ReportSource=null;
ReportDocument rep=新的ReportDocument();
rep=GetReport(列表框1.SelectedIndex);
crView.ReportSource=rep;
这个.crView.RefreshReport();
}
私有报告文档GetReport(INTP)
{
返回lr[p].reportDocument;
}
}
现在问题是:当我点击列表框中的项目时,在查看器中只显示最后一个报告。有两个名称不同的项目,但只有一个报告。 如果我尝试在form1中为每个创建的报表显示报表,则值和报表都可以,但在selectedindexchanged事件中,两个报表文档是相同的。 请问错误在哪里? 如何更新crzstal报告,以便显示正确的数据


提前谢谢。

Hmmmm。我建议您尝试调试。很好的尝试,stackoverflow不是jira。谢谢,我当然试过调试。对不起,这太轻率了。我的意思是问“我的代码中有一个bug”这类问题并不是在这个网站上获得帮助的最佳方式。我们最好能帮你做点什么。
List<Report> lr = null;
    public ReportViewer()
    {
        InitializeComponent();
    }

    public ReportViewer(List<Report> reports) : this()
    {
        lr = reports;
        foreach (Report report in reports)
        {
            listBox1.Items.Add(report.Name);
        }
        listBox1.SelectedIndex = 0;
    }

    private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        crView.ReportSource = null;
        ReportDocument rep = new ReportDocument();
        rep = GetReport(listBox1.SelectedIndex);
        crView.ReportSource = rep;
        this.crView.RefreshReport();

    }

    private ReportDocument GetReport(int p)
    {
        return lr[p].reportDocument;
    }
}