Domanda

i am working on windows form application...i have a crystal report...for showing crystal report in button click event i given code like this:

SqlCommand cmdrslt = new SqlCommand("rptdeptwisevisitor", con.connect);
cmdrslt.CommandType = CommandType.StoredProcedure;
cmdrslt.Parameters.Add("@startDate", SqlDbType.NVarChar, 50, ParameterDirection.Input).Value = frmdateval;
cmdrslt.Parameters.Add("@endDate", SqlDbType.NVarChar, 50, ParameterDirection.Input).Value = Todateval;
SqlParameter tvp1 = cmdrslt.Parameters.AddWithValue("@Dept", DepTable);
tvp1.SqlDbType = SqlDbType.Structured;
tvp1.TypeName = "dbo.Dept";
da.SelectCommand = cmdrslt;
da.Fill(ds);
DeptWiseRpt rpt = new DeptWiseRpt();
if ((ds.Tables(0).Rows.Count > 0)) {
    rpt.SetDataSource(ds.Tables(0));
    rpt.SetParameterValue("frmd", setparmstartd);
    rpt.SetParameterValue("tod", setparmendd);
    CrystalReportViewer1.ReportSource = rpt;

}

this is taking time to load the data..so i want to put a progress bar on this form..how could I put it?
any help is very appreciable...

È stato utile?

Soluzione

Loading report is a single operation (two at most: query and displaying the viewer), so that you can't split it do display progress accurately. You could display progressless bar or use animated image like this one:

enter image description here

That operation has to run in parallel to UI thread (use Thread, Task or BackgroundWorker), otherwise your progress (progressbar or image) will not get updated even once. For the time of loading you should not display report viewer itself (make it invisible or size 1x1). Once loading is completed: hide progress and display viewer.

Some code:

// hide viewer, show progress
CrystalReportViewer1.Visible = false;
pictureBoxProgress.Visible = true;
// start thread
(new Thread(() => {

    // your code
    SqlCommand cmdrslt = new SqlCommand("rptdeptwisevisitor", con.connect);
    cmdrslt.CommandType = CommandType.StoredProcedure;
    cmdrslt.Parameters.Add("@startDate", SqlDbType.NVarChar, 50, ParameterDirection.Input).Value = frmdateval;
    cmdrslt.Parameters.Add("@endDate", SqlDbType.NVarChar, 50, ParameterDirection.Input).Value = Todateval;
    SqlParameter tvp1 = cmdrslt.Parameters.AddWithValue("@Dept", DepTable);
    tvp1.SqlDbType = SqlDbType.Structured;
    tvp1.TypeName = "dbo.Dept";
    da.SelectCommand = cmdrslt;
    da.Fill(ds);
    DeptWiseRpt rpt = new DeptWiseRpt();
    if ((ds.Tables(0).Rows.Count > 0)) {
        rpt.SetDataSource(ds.Tables(0));
        rpt.SetParameterValue("frmd", setparmstartd);
        rpt.SetParameterValue("tod", setparmendd);
        // controls operations require invoke
        BeginInvoke(() => {
            CrystalReportViewer1.ReportSource = rpt;
            pictureBoxProgress.Visible = false;
            CrystalReportViewer1.Visible = true;
        });
    }
})).Start();
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top