This is a migrated thread and some comments may be shown as answers.

Am in Preview mode?

1 Answer 49 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Michael Million
Top achievements
Rank 1
Michael Million asked on 18 Jun 2010, 10:50 PM
Hi,

Forgive me if this has already been answered in this forum already.  I could not find it.

Is it possible to know if the environment is in report preview mode versus actually running a report?

I'd like to do something like this in the report class, derived from Telerik.Reporting.Report:

....
if ( InReportDesignPreviewMode )
{

    this

 

.DataSource = MyBusinessClass.LoadTestData();
}
else
{
    this.DataSource = MyBusinessClass.LoadRealData();
}
...

I did try this.DebugMode() and it didn't behave as I thought it would.

Thanks for your input on this matter.

Michael

1 Answer, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 21 Jun 2010, 08:52 AM
Hi Michael Million,

The only way to distinguish the design time execution of the report from the run-time is that in the first case the designer instantiates the report, while in the other case you have full control over it and not only the ability to preview. Below is a sample code that illustrates one of the ways you can do this.

Initialize the Report.DataSource with the design time data source object:

class MyReport()
{
    public MyReport()
    {
        InitializeComponent();
          
        try
        {
            this.DataSource = designDataSource;
        }
        catch 
        {
        }
    }
}

and then before displaying the report in the report viewer (run-time) override it with the real data source object:

MyReport myReport = new MyReport();
myReport.DataSource = realDataSource;
this.reportViewer1.Report = myReport;

Another approach is to use the application's settings or the config files where you can store different connection strings or whatever you need (remember that you should use the Visual Studio' config file - devenv.exe.config when working with the designer).

Anyway we would consider whether we can make any improvements to differentiate whether the report is in preview while working on subsequent versions.

Sincerely yours,
Steve
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Michael Million
Top achievements
Rank 1
Answers by
Steve
Telerik team
Share this question
or