DesignMode property

2 posts, 0 answers
  1. Emil Alexiev
    Emil Alexiev avatar
    8 posts
    Member since:
    Dec 2009

    Posted 06 Jun 2011 Link to this post

    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.
  2. Steve
    Steve avatar
    10941 posts

    Posted 07 Jun 2011 Link to this post

    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() 
                this.DataSource = designDataSource; 

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

    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
  3. DevCraft R3 2016 release webinar banner
Back to Top