Click here to Skip to main content
15,902,112 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Frnds

I have developed one sales screen.. but i dont knw how to give print the crystal report using print button in C#.
please help me..



With Regards,
Vino.
Posted

1 solution

Try This

use crystal reportviewer it gives you print button by default

for more information goto
Creating Crystal Reports using C# with Datasets[^]
 
Share this answer
 
Comments
Member 10611310 4-Mar-14 6:56am    
i no need report viewer default button. in sales screen i gave print button. i click print button print the entire fields..
GaneshKale22 4-Mar-14 7:06am    
if your working with web form then place your crystal report in <Div></Div> tags then use this javascript..

function printDiv() {
var divToPrint = document.getElementById('printArea');
newWin= window.open();
newWin.document.write(divToPrint.innerHTML);
newWin.document.close();
newWin.focus();
newWin.print();
newWin.close();
}
GaneshKale22 4-Mar-14 7:14am    
ok... then use this i am using this and working...

private void btnPrint_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();

ReportDocument crReportDocument;
crReportDocument = new ReportDocument();
//Create an instance of a report
crReportDocument = new KMAAccounts.Reports.GL.rptDebitVoucherS();
string Query = "exec SP_DebitVoucher @PaymentId,@CompanyCode";
Query = Query.Replace("@PaymentId", "'" + txtPayment.Text + "'");
Query = Query.Replace("@CompanyCode", "'" + log.GetCompanyCode() + "'");

dt = GetDataTable(Query);
crReportDocument.SetDataSource(dt);
//Use error handling in case an error occurs
try
{
//Set the printer name to print the report to. By default the sample
//report does not have a defult printer specified. This will tell the
//engine to use the specified printer to print the report. Print out
//a test page (from Printer properties) to get the correct value.

System.Drawing.Printing.PrintDocument printDocument = new System.Drawing.Printing.PrintDocument();
crReportDocument.PrintOptions.PrinterName = printDocument.PrinterSettings.PrinterName;


//Start the printing process. Provide details of the print job
//using the arguments.
crReportDocument.PrintToPrinter(1, true, 0, 0);

//Let the user know that the print job is completed
MessageBox.Show("Report finished printing!");
}
catch (Exception err)
{
MessageBox.Show(err.ToString());
}

}
Member 10611310 4-Mar-14 7:13am    
am using Windows application..
GaneshKale22 4-Mar-14 7:16am    
Bro this code is only for windows application

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900