May I know where you are stuck now?
Do you not know how to load the data using the report viewer, or how to print it after loading?
In the first case, you can follow the steps below:
- Right click on the item => Add=> New Item => Report/Report Wizard.
In my memory, this step before will only produce a blank Report, but now it includes all the steps to generate a DataSet to connect to the database.
I'm not sure if my usage is wrong. The table produced in this way seems to have to include calculations. If we just want to display the current data, then we can delete the table produced in this step and add it by ourselves using the steps below. - Add a DataSet.
- Add a table and add the required columns.
- Add Report Viewer to winform and bind the report we added as a data source.
If it is the second case, then we can use the while loop in the Task to determine the reportViewer1.CurrentStatus.CanPrint
property.
private void Form1_Load(object sender, EventArgs e)
{
this.ScoreTableTableAdapter.Fill(this.TestDataSet.ScoreTable);
this.reportViewer1.RefreshReport();
Task.Run(() =>
{
while (true)
{
if (reportViewer1.CurrentStatus.CanPrint)
{
this.Invoke(new MethodInvoker(delegate
{
this.reportViewer1.PrintDialog();
}));
break;
}
}
});
}
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.