¿Hay alguna forma de eliminar la caché o memoria de la información que se queda en un reportviewer? Estoy trabajando con visual studio 2010 y winform.
Me pasa lo siguiente: al cargar por primera vez mi reporte se muestra de manera correcta, pero si cambio de reporte y regreso nuevamente al primero que abrí, se queda colgado en cargando.
Había leído que antes de la sentencia del DataSource se podía poner una sentencia para borrar los datos en memoria pero no recuerdo cómo es.
BeneficiariesDebtsViewer.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace CheckManagement
{
public partial class BeneficiariesDebtsViewer : Form
{
BeneficiariesDebts debts;
public BeneficiariesDebtsViewer()
{
InitializeComponent();
}
private void BeneficiariesDebtsViewer_Load(object sender, EventArgs e)
{
try
{
beneficiariesDebts.Clear();
LoadBeneficiaryDebts loader = new LoadBeneficiaryDebts();
//BeneficiariesDebts debts = loader.LoadData();
debts = loader.LoadData();
foreach (BeneficiariesDebts.BeneficieriesDebtsTableRow row in debts.BeneficieriesDebtsTable)
{
beneficiariesDebts.BeneficieriesDebtsTable.AddBeneficieriesDebtsTableRow(row.BeneficiaryID, row.BeneficiaryName, row.TotalDebt, row.BeneficiariesTypes);
}
this.reportViewer1.RefreshReport();
}
catch (System.Exception ex)
{
MessageBox.Show("Hubo un problema al realizar la operación:\n" + ex.Message,
"", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void BeneficiariesDebtsViewer_FormClosing(object sender, FormClosingEventArgs e)
{
MessageBox.Show("Se cerró la ventana");
beneficiariesDebts.BeneficieriesDebtsTable.Rows.Clear();
debts.Clear();
//debts.BeneficieriesDebtsTable.Clear();
//reportViewer1.Clear();
}
}
}
BeneficiariesDebtsViewer.Designer.cs
namespace CheckManagement
{
partial class BeneficiariesDebtsViewer
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
Microsoft.Reporting.WinForms.ReportDataSource reportDataSource1 = new Microsoft.Reporting.WinForms.ReportDataSource();
this.reportViewer1 = new Microsoft.Reporting.WinForms.ReportViewer();
this.beneficiariesDebts = new CheckManagement.BeneficiariesDebts();
this.beneficieriesDebtsTableBindingSource = new System.Windows.Forms.BindingSource(this.components);
((System.ComponentModel.ISupportInitialize)(this.beneficiariesDebts)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.beneficieriesDebtsTableBindingSource)).BeginInit();
this.SuspendLayout();
//
// reportViewer1
//
this.reportViewer1.Dock = System.Windows.Forms.DockStyle.Fill;
reportDataSource1.Name = "BeneficiariesDebts_BeneficieriesDebtsTable";
reportDataSource1.Value = this.beneficieriesDebtsTableBindingSource;
this.reportViewer1.LocalReport.DataSources.Add(reportDataSource1);
this.reportViewer1.LocalReport.ReportEmbeddedResource = "CheckManagement.DebtsReport.rdlc";
this.reportViewer1.Location = new System.Drawing.Point(0, 0);
this.reportViewer1.Name = "reportViewer1";
this.reportViewer1.Size = new System.Drawing.Size(926, 504);
this.reportViewer1.TabIndex = 0;
//
// beneficiariesDebts
//
this.beneficiariesDebts.DataSetName = "BeneficiariesDebts";
this.beneficiariesDebts.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema;
//
// beneficieriesDebtsTableBindingSource
//
this.beneficieriesDebtsTableBindingSource.DataMember = "BeneficieriesDebtsTable";
this.beneficieriesDebtsTableBindingSource.DataSource = this.beneficiariesDebts;
//
// BeneficiariesDebtsViewer
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(926, 504);
this.Controls.Add(this.reportViewer1);
this.Name = "BeneficiariesDebtsViewer";
this.ShowIcon = false;
this.Text = "Saldos pendientes";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Load += new System.EventHandler(this.BeneficiariesDebtsViewer_Load);
((System.ComponentModel.ISupportInitialize)(this.beneficiariesDebts)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.beneficieriesDebtsTableBindingSource)).EndInit();
this.ResumeLayout(false);
}
#endregion
private Microsoft.Reporting.WinForms.ReportViewer reportViewer1;
private System.Windows.Forms.BindingSource beneficieriesDebtsTableBindingSource;
private BeneficiariesDebts beneficiariesDebts;
}
}
La declaración BeneficiariesDebts debts es "Represent a strongly typed in-memory cache of data"; quiero hacer uno del evento FormClosing y limpiar la caché pero no he encontrado la manera de hacerlo. Agregué lo siguiente pero no funciona:
private void BeneficiariesDebtsViewer_FormClosing(object sender, FormClosingEventArgs e)
{
MessageBox.Show("Se cerró la ventana");
beneficiariesDebts.BeneficieriesDebtsTable.Rows.Clear();
debts.Clear();
//debts.BeneficieriesDebtsTable.Clear();
//reportViewer1.Clear();
}