Reports for WinForms | ComponentOne
Using the C1ReportDesigner Control / Step 5 of 9: Implement the SetDesignMode Method
In This Topic
    Step 5 of 9: Implement the SetDesignMode Method
    In This Topic

    The simple designer has two modes: report design and preview. When the user selects a new report or clicks the Design button on the toolbar, the application shows the designer control. When the user clicks the Preview button, the application renders the current report into the preview control and shows the result.

    Add the following code to implement the SetDesignMode method:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Private Sub SetDesignMode(ByVal design As Boolean)        
        ' show/hide preview/design panes        
        _c1rd.Visible  = design        
        _c1ppv.Visible = Not design
       
        ' no properties in preview mode        
        If Not design Then        
            _lblPropGrid.Text = "Properties"        
            _ppg.SelectedObject = Nothing        
        End If
      
        ' attach copy of the report to preview control        
        ' (so changes caused by script aren't saved)        
        If Not design Then        
            _c1ppv.Document = Nothing        
            _c1r.CopyFrom(_c1rd.Report)        
            Cursor = Cursors.WaitCursor        
            _c1r.Render()        
            If _c1r.PageImages.Count > 0 Then        
                _c1ppv.Document = _c1r        
            End If        
            Cursor = Cursors.Default        
        End If
     
        ' done, update UI        
        UpdateUI()        
    End Sub
    

    To write code in C#

    C#
    Copy Code
    private void SetDesignMode( bool design)         
    {        
        // show/hide preview/design panes        
        _c1rd.Visible  = design;        
        _c1ppv.Visible = !design;
    
        // no properties in preview mode        
        if (!design )         
        {        
            _lblPropGrid.Text = "Properties";        
            _ppg.SelectedObject = null;        
        }
        
        // attach copy of the report to preview control        
        // (so changes caused by script aren't saved)        
        if (!design )         
        {        
            _c1ppv.Document = null;        
            _c1r.CopyFrom(_c1rd.Report);        
            Cursor = Cursors.WaitCursor;       
            _c1r.Render();        
            if (_c1r.PageImages.Count > 0 )        
                _c1ppv.Document = _c1r;        
            Cursor = Cursors.Default;        
        }
    
        // done, update UI         
        UpdateUI();        
    }
    

    Switching to design mode is easy, all you have to do is show the designer and hide the preview control. Switching to preview mode is a little more involved because it also requires rendering the report.

    Note that the report is copied to a separate C1Report control before being rendered. This is necessary because reports may contain script code that changes the report definition (field colors, visibility, and so on), and we don't want those changes applied to the report definition.