Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Setting report page size dynamically (Read 10529 times)
Vikas Kumar
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 18
Joined: Mar 1st, 2011
Setting report page size dynamically
Mar 30th, 2011 at 8:06am
Print Post  
Hi Meppy

I need your help to set the width of report page dynamically based on screen resolution. My report is displayed inside a report window control and i want its size to be same as of report window. My present screen resolution(1600 by 900)
My report is inside the reportwindow.xaml control.
The report control fits itself according to screen resolution but not the report inside and so there comes a gap on the right side.
Code
Select All
<Grid x:Name="LayoutRoot">

<Border CornerRadius="5" BorderBrush="#FF28607C" BorderThickness="1">


<Border.Background>



<LinearGradientBrush EndPoint="0.966,0.479" StartPoint="0.002,0.488">




<GradientStop Color="#FF65B1F0"/>




<GradientStop Color="#FFACE8F0" Offset="1"/>



</LinearGradientBrush>


</Border.Background>


<Grid>



<Grid.RowDefinitions>




<RowDefinition Height="26"/>




<RowDefinition Height="22*"/>
                    <RowDefinition Height="423*" />
                </Grid.RowDefinitions>




<Border x:Name="Header" Grid.Row="0" CornerRadius="4,4,0,0">



<Border.Background>




<LinearGradientBrush EndPoint="0.17,0.033" StartPoint="0.17,1.032">





<GradientStop Color="#FF134C6C" Offset="0"/>





<GradientStop Color="#FF2A627E" Offset="1"/>




</LinearGradientBrush>



</Border.Background>



<TextBlock HorizontalAlignment="Left" x:Name="Title" TextWrapping="Wrap" Text="RESULTS: MAGAZINES Plan 1" VerticalAlignment="Center" Style="{StaticResource HeadingReport}" Margin="3,0,0,0" FontFamily="AvantGarde Bk BT" Foreground="White"/>



</Border>



<Border Background="White" Grid.Row="1" CornerRadius="0,0,3,3" Margin="3" BorderBrush="#FF1F4F6B" BorderThickness="1" Grid.RowSpan="2"></Border>
                <report:ReportViewer Name="reportViewer" Grid.Row="1"  Grid.RowSpan="2" Margin="5" PageMargins="0" Style="{StaticResource ReportViewerStyle1}" />
            </Grid>



</Border>


</Grid>

 



I have a report handler class where I have tried to set the report viewer size.
Code
Select All
 if (report != null)
            {

                if (_prvm != null)
                {
                    report.DataContext = _prvm;
                }

                report.QueryDetails += new EventHandler<QueryDetailsEventArgs>(report_QueryDetails);

                report.Run();
                if (_reportControl != null)
                {
                    _reportControl.reportViewer.PageSize = new Size(_reportControl.ActualWidth, _reportControl.reportViewer.PageSize.Height);

                    //foreach (var page in report.Pages)
                    //{
                    //    page.Size = new Dimension(_reportControl.ActualWidth, _reportControl.ActualHeight);
                    //}

                    _reportControl.reportViewer.Document = report;
                }
            }

 



But when the first time the report is loaded it doest change the page size and takes the default value. On consecutive calls the size is changed.

Please help me solve this issue.

Regards
Vikas
  
Back to top
 
IP Logged
 
Vikas Kumar
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 18
Joined: Mar 1st, 2011
Re: Setting report page size dynamically
Reply #1 - Mar 30th, 2011 at 8:27am
Print Post  
Hi Meppy

I just found one solution by setting the size in report_prerender event.

Code
Select All
private void report_Prerender(object sender, PrerenderEventArgs e)
       {

           _reportControl.reportViewer.PageSize = new Size(_reportControl.ActualWidth, _reportControl.reportViewer.PageSize.Height);

       }

 



Is there any better way to do this.
Regards
Vikas
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Setting report page size dynamically
Reply #2 - Mar 30th, 2011 at 8:57am
Print Post  
Setting the size in the Prerender event is not a really good choice since this event is invoked multiple times for items in the report. Not to mention that setting the ReportViewer.PageSize itself causes a rendering of the report. The most natural place to put this code is in the SizeChanged event of the ReportViewer or its container - _reportControl.

I am trying this and it works as expected. Where were you calling this code originally?

Regards,
Meppy
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Setting report page size dynamically
Reply #3 - Mar 30th, 2011 at 9:10am
Print Post  
Additional note: It appears that selecting a new document in the ReportViewer causes the previously set PageSize to be discarded. Try reversing the assignment order by first setting Document, then setting PageSize.

Regards,
Meppy
  
Back to top
 
IP Logged
 
Vikas Kumar
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 18
Joined: Mar 1st, 2011
Re: Setting report page size dynamically
Reply #4 - Apr 5th, 2011 at 11:28am
Print Post  
Hi Meppy,
Sorry for the late reply. I was busy with another work so couldn't get time to reply earlier.

Thanks for the suggestion. I tried changing the page size in both reporttcontrol and report viewer size changed events but it didn't work. But as u suggested later to do the page size change after assigning the report to the document . I tried that and it worked.


Code
Select All
                if (_reportControl != null)
                {

                    report.Prerender += new EventHandler<PrerenderEventArgs>(report_Prerender);
                    _reportControl.reportViewer.Document = report;
                    _reportControl.reportViewer.PageSize = new Size(_reportControl.ActualWidth, _reportControl.reportViewer.PageSize.Height);

                }

 



Thanks again!!
Regards
Vikas
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint