'How to solve the infinite loop in reportviewer? winforms

I am working with reportviewer in visual studio 2010, but when I open the report for the first time the data loads correctly, but when I change to another report and try to return to the first one, the reportviewer stays on loading.

I tried with IsPostBack but it gives me an error.

error

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
{
    public BeneficiariesDebtsViewer()
    {
        InitializeComponent();
    }

    private void BeneficiariesDebtsViewer_Load(object sender, EventArgs e)
    {
        try
        {
            if (!IsPostBack)
            {
                // Report data source code...
                reportViewer1.RefreshReport();
            }

            beneficiariesDebts.Clear();
            LoadBeneficiaryDebts loader = new LoadBeneficiaryDebts();                
            BeneficiariesDebts debts = loader.LoadData();

            foreach (BeneficiariesDebts.BeneficieriesDebtsTableRow row in debts.BeneficieriesDebtsTable)
            {
                beneficiariesDebts.BeneficieriesDebtsTable.AddBeneficieriesDebtsTableRow(row.BeneficiaryID, row.BeneficiaryName, row.TotalDebt, row.BeneficiariesTypes);
            }

            reportViewer1.RefreshReport();
        }
        catch (System.Exception ex)            
        {
            MessageBox.Show("Hubo un problema al realizar la operación:\n" + ex.Message,
                            "", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }            
    }
  }
}

I really appreciate your attention and help.



Solution 1:[1]

I was able to solve it in the following way:

try
        {
            
            beneficiariesDebts.Clear();

            LoadBeneficiaryDebts loader = new LoadBeneficiaryDebts();
            BeneficiariesDebts debts = loader.LoadData();

            foreach (BeneficiariesDebts.BeneficieriesDebtsTableRow row in debts.BeneficieriesDebtsTable)
            {
                beneficiariesDebts.BeneficieriesDebtsTable.AddBeneficieriesDebtsTableRow(row.BeneficiaryID, row.BeneficiaryName, row.TotalDebt, row.BeneficiariesTypes);
            }


            this.reportViewer1.RefreshReport();
            MessageBox.Show("La carga puede tardar unos minutos","Nota");

        }

I added a MessageBox.Show which allows the page to reload and in this way I managed to prevent the report from hanging.

Solution 2:[2]

IsPostBack doesn't exist in a winform project but only in Asp.net.

Try to delete the if with IsPostBack and rerun the project.

Luc

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ana Pimentel
Solution 2 lucdm