1

我在 Form2 中有以下代码

public void authorisedList()
    {
        using (myContext v = new myContext())
        {
            DateTime date = DateTime.Today.AddMonths(-12);

            var myList = (from l in v.AuthorisedList
                                            where l.FromDate >= date
                                            select new
                                            {
                                                l.ID,
                                                l.EmpName,
                                                l.StartDate,
                                                l.EndDate,
                                                l.Days,
                                                l.Approved,
                                                l.Confirmed,
                                            }).ToList();

            reportViewer1.LocalReport.DataSources.Clear();
            ReportDataSource datasource = new ReportDataSource("MyReportsDatasource", myList);
            reportViewer1.LocalReport.DataSources.Add(datasource);

            string exeFolder = Path.GetDirectoryName(Application.ExecutablePath);
            string reportPath = Path.Combine(exeFolder, @"rdlcReports\Authorised List.rdlc");

            reportViewer1.LocalReport.ReportPath = reportPath;
            reportViewer1.RefreshReport();
        }
    }

然后在Form2的父Form1中,我在单选按钮中有以下代码

 private void radioButton1_CheckedChanged(object sender, EventArgs e)
    {
        Form2 au = new Form2(this);
        au.authorisedList();
    }

问题是,当我检查 Form1 中的 radioButton 控件(radioButton1)时,Form2 中的 authorisedList() 似乎正在执行,但 reportViewer 报告没有更新/更改。

我想知道为什么。

4

1 回答 1

0

如果您Form2已经打开,那么您应该获取打开表单的对象,然后调用其authorisedList()方法。你可以使用Application.OpenForms属性。

private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
    Form2 au = Application.OpenForms["Form2"] as Form2;
    if(au != null)
           au.authorisedList();
}
于 2013-02-20T10:13:46.160 回答