none
Help on: Two or more reports on the same report viewer RRS feed

  • Question

  • Hi, well I put this case simple
    I have a main app with two Buttons (Rep01 and Rep02) and an additional window that contains the report viewer control

    What I want to do is to view the Report01 when I click the button Rep01 and the Report02 when I click the Rep02 button but I want to use the same window.
    I don't care to open different instances of teh window, i want to dynamically assign the corresponding report.

    I need help at this 'cause if I insert the ReportViewer I see that you can statically assign THE report that is going to be shown but I don't want to create a window for each report. I want to send (if possible) the report itself as parameter.

    Any help?


    Wednesday, June 6, 2007 11:00 PM

All replies

  • I'm not sure I follow your problem.

    You can change the reportSource of the report viewer at runtime.

    The simplest change I can suggest is passing the report source name as a parameter within the constructor, then set the report viewer's .ReportSource property after the InitializeComponent call.

    So in your calling code (buttons) you'd have something like:
    //(report 1 button)
    Report01_Click(object sender, EventArgs e)
    {
        PreviewWindow myPreview = new PreviewWindow("rep01.rpt");
        myPreview.ShowDialog();
    }



    //And the Constructor inside PreviewWindow:
    public PreviewWindow(string reportSource)
    {
        InitializeComponent();
        //Where ReportPreview is the name of the report viewer control.
        ReportPreview.ReportSource = reportSource;

    }
    Thursday, June 7, 2007 1:52 AM
  • I forgot to mention... I'm not using Crystal reports. I'm using the ReportViewer controls that comes with Visual Studio 2005 Standar Edition
    Thursday, June 7, 2007 2:27 AM
  • Ah, I see, that is a bit different. Unfortunately I don't use the MS Report Viewer myself, but from I can see it should still be possible to change the report reference.

    If it is a local report you are viewing, try setting:
    ReportViewer.LocalReport.ReportPath

    You'll probably need to issue a RefreshReport on the viewer itself to trigger a re-render.

    Cheers,
    Thursday, June 7, 2007 4:30 AM
  • What you need to use is the following:

     

    reportViewer1.Reset();

     

    This is the only way (that I have seen) to be able to switch between reports. By using refresh, you can change the report being loaded but the DataSources remain the same....(or so it does seem)!

     

    i hope this helps!

    Thursday, June 7, 2007 5:52 PM