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

DesignMode property

1 Answer 147 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Emil Alexiev
Top achievements
Rank 1
Emil Alexiev asked on 06 Jun 2011, 06:34 PM
Hi,
I was wondering if DesignMode property works.  I would expect it to be true when previewing the report in visual studio designer and false at runtime.  I want to use it to set report DataSource to null in report constructor at runtime, but not at design time because otherwise my report won't process in design time.
Emil.

1 Answer, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 07 Jun 2011, 08:05 AM
Hello Emil,

The actual reason that the Report.DesignMode property (derived from System.ComponentModel.DesignMode) returns false while previewing a report is that the report is not sited. For the sake of the previews another instance of the report is being created (to be precise the component designer operates with an instance of the base class - that in the case of Telerik Reporting is usually the Telerik.Reporting.Report class).

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 the 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).

Greetings,
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
Emil Alexiev
Top achievements
Rank 1
Answers by
Steve
Telerik team
Share this question
or