Hi All,
I just tried the following concept to print without viewing report.
DialogResult ans = MessageBox.Show("Want Print Preview?", "App Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (ans == DialogResult.No)
{
Int32 OrderID = Convert.ToInt32(dgvOrders.SelectedRows[0].Cells["OrdID"].Value);
ReportViewer _reportviewer = new ReportViewer();
LocalReport _localReport = _reportviewer.LocalReport;
_localReport.ReportPath = AppDomain.CurrentDomain.BaseDirectory + "..\\..\\Jobs\\PrintOrder.rdlc";
this.tblOrderItemsTableAdapter.Fill(this.billDataSet.tblOrderItems, OrderID);
this.tblOrderTableAdapter.Fill(this.billDataSet.tblOrder, OrderID);
ReportDataSource _reportDataSource1 = new ReportDataSource();
_reportDataSource1.Name = "BillDataSet_tblOrder";
_reportDataSource1.Value = this.billDataSet.tblOrder;
ReportDataSource _reportDataSource2 = new ReportDataSource();
_reportDataSource2.Name = "BillDataSet_tblOrderItems";
_reportDataSource2.Value = this.billDataSet.tblOrderItems;
_localReport.DataSources.Add(_reportDataSource1);
_localReport.DataSources.Add(_reportDataSource2);
_reportviewer.RenderingComplete += new RenderingCompleteEventHandler(_reportviewer_RenderingComplete);
_reportviewer.RefreshReport();
}
else
{
FormPrntOrd _Order = new FormPrntOrd(Convert.ToInt32(dgvOrders.SelectedRows[0].Cells[0].Value));
_Order.ShowDialog(this);
}
We can call _reportviewer.Print() or _reportviewer.PrintDialog() in _reportviewer_RenderingComplete. The _reportviewer should be declare in partial class.