Thursday, May 5, 2016

Change RDLC window to UserControl

Leave a Comment

Hello at the moment when I click my "Business Listing" button it'll display my report window with the appropriate information. I'm trying to have it display within my ShellView instead of a "window pop up".

Old Code

PreviewForm.xaml

<Window .......     <Grid>           <WindowsFormsHost Name="MyHost" Margin="0,0,0,0" Visibility="Visible">              <rv:ReportViewer x:Name="_reportViewer" ForeColor="AliceBlue" Visible="True" Dock="Fill"/>         </WindowsFormsHost>     </Grid> </Window> 

PreviewForm.xaml.cs

public string reportSource { get; set; } public Microsoft.Reporting.WinForms.ReportDataSource reportDataSource { get; set; }  private void Window_Loaded(object sender, RoutedEventArgs e) {     try     {         this._reportViewer.Reset();         this._reportViewer.LocalReport.ReportEmbeddedResource = this.reportSource;         this._reportViewer.LocalReport.DataSources.Clear();         this._reportViewer.LocalReport.DataSources.Add(this.reportDataSource);         this._reportViewer.LocalReport.Refresh();         this._reportViewer.RefreshReport();     }     catch (Exception Ex)     {         Ex.ToString();     } } 

ReportViewModel

public void BusinessListing() {     try     {         BindableCollection<BusinessDTO> Firms;         using (var ctx = DB.Get())         {             Firms = new BindableCollection<BusinessDTO>(BusinessDTO.ReportBusiness(ctx));         }          Microsoft.Reporting.WinForms.ReportDataSource reportDataSource1 = new            Microsoft.Reporting.WinForms.ReportDataSource();         reportDataSource1.Name            = "BusinessDTO";         reportDataSource1.Value           = Firms;         Reports.ReportPreviewForm preview = new Reports.ReportPreviewForm();         preview.reportDataSource          = reportDataSource1;         preview.reportSource              = "Reports.ListingReports.BusinessListingReport.rdlc";         preview.Show();     }     catch (Exception Ex)     {         MessageBox.Show(Ex.Message);     } } 

ReportGridView

<shell:GridScreenControl.Grid>     <Grid >         <panes:ReportPreviewForm/>     <Grid > </shell:GridScreenControl.Grid> 

Additions.

I converted PreviewForm to a UserControl.

Changed Window_Loaded =>

public void Update() 

and in my ReportViewModel instead of preview.Show() I have preview.Update() It currently just shows a blank white screen.

2 Answers

Answers 1

I think you need to tell your pane to fill the grid? In your original code you had Dock="Fill" to tell the report to fill the window. Why don't you try this or adding some fixed heights and widths to the grid, pane and window to see if this is the issue.

You can also set the background colors of the window (say blue) and grid (say green) to see if they are indeed being covered by the pane.

This is not the most scientific approach but gives you some visual tools to work with. There are also tools like WPF Snoop that can help.

Answers 2

Maybe you need to add a dispatcher to your update method, because your call originates from the viewmodel now:

private Dispatcher _dispatcher; // In class _dispatcher = Dispatcher.CurrentDispatcher; // In constructor  public void Update() {     try     {         _dispatcher.BeginInvoke(new Action(() =>         {             this._reportViewer.Reset();             this._reportViewer.LocalReport.ReportEmbeddedResource = this.reportSource;             this._reportViewer.LocalReport.DataSources.Clear();             this._reportViewer.LocalReport.DataSources.Add(this.reportDataSource);             this._reportViewer.LocalReport.Refresh();             this._reportViewer.RefreshReport();         }));     }     catch (Exception Ex)     {         Ex.ToString();     } } 
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment