Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying Crystal Report in Windows form

Status
Not open for further replies.

hne

Programmer
Oct 16, 2003
38
US
Hello,
I am using VS.NET and Crystal Report 10. How can I display my Crystal Report Form in C#? When I call my Crystal Report class from another class (Form1.cs) it fails to load the form.
i.e.: Form1.cs
display_myform.csForm crViewer1 = new csForm();

In my Crystal Report form csForm.cs, I have a method event called csForm_Load(object sender, System.EventArgs e). However, from Form1.cs when get into csForm.cs, my app fails to load the method.

Thanks for your help.
 
This is how I do it.

Create a form with the crviewer drawn on it.

Create rpt files within your project by clicking add new item - choose crystal report - design your report.

load your form with crview and set reportSource to the rpt you wish.



What it appears you are doing is trying to set a viewer object = to a form and that ain't gonna happen!

--------Here is my code from the viewer form. I have a global variable caller _reportName which triggers the action when the page loads. _reportData is a global dataset which contains the data for the report.



private void frmReport_Load(object sender, System.EventArgs e)
{
this.CenterToScreen();
switch(_reportName)
{
case "rptInventoryListWithoutPriceInStock":
goto case "rptListWithUnitPriceFull";
case "rptListWithUnitPriceInStock":
goto case "rptListWithUnitPriceFull";
case "rptListWithoutUnitPriceFull":
goto case "rptListWithUnitPriceFull";

case "rptListWithUnitPriceFull":
rptInventoryList rpt = new rptInventoryList();
rpt.SetDataSource(_reportData);
rptMain.ReportSource = rpt;
break;
case "InventoryListbyMetalType":
rptInventoryListByMetalType rpt2 = new rptInventoryListByMetalType();
rpt2.SetDataSource(_reportData);
rptMain.ReportSource = rpt2;
break;
case "rptBelowMinimumStock":
rptInventoryBelowMinimum rpt3 = new rptInventoryBelowMinimum();
rpt3.SetDataSource(_reportData);
rptMain.ReportSource = rpt3;
break;
case "rptOutstandingPOList":
rptOutstandingPOList rpt4 = new rptOutstandingPOList();
rpt4.SetDataSource(_reportData);
rptMain.ReportSource = rpt4;
break;
case "rptCurrentInventoryCost":
rptCurrentInventoryCost rpt5 = new rptCurrentInventoryCost();
rpt5.SetDataSource(_reportData);
rptMain.ReportSource = rpt5;
break;
case "rptInventoryPricehistory":
rptPriceHistory rpt6 = new rptPriceHistory();
rpt6.SetDataSource(_reportData);
rptMain.ReportSource = rpt6;
break;
case "rptInventoryCostbyMetalType":
rptCostOfInventoryByMetalType rpt7 = new rptCostOfInventoryByMetalType();
rpt7.SetDataSource(_reportData);
rptMain.ReportSource = rpt7;
break;
case "rptMetalList":
rptMetalList rpt8 = new rptMetalList();
rpt8.SetDataSource(_reportData);
rptMain.ReportSource = rpt8;
break;
case "rptPriceHistory":
rptPriceHistory rpt9 = new rptPriceHistory();
rpt9.SetDataSource(_reportData);
rptMain.ReportSource = rpt9;
break;
case "rptInventoryOnOrder":
rptInventoryOnOrder rpt10 = new rptInventoryOnOrder();
rpt10.SetDataSource(_reportData);
rptMain.ReportSource = rpt10;
break;
case "rptVendorInventory":
rptVendorSupplyList rpt11 = new rptVendorSupplyList();
rpt11.SetDataSource(_reportData);
rptMain.ReportSource = rpt11;
break;
case "ContractPriceList":
rptCustomerContractPricing rpt12 = new rptCustomerContractPricing();
rpt12.SetDataSource(_reportData);
rptMain.ReportSource = rpt12;
break;
case "rptSales":
rptSalesSummary rpt13 = new rptSalesSummary();
rpt13.SetDataSource(_reportData);
rptMain.ReportSource = rpt13;
break;

case "rptCustomerAddresses":
rptCustomerAddresses rpt14 = new rptCustomerAddresses();
rpt14.SetDataSource(_reportData);
rptMain.ReportSource = rpt14;
break;

case "rptVendorAddresses":
rptVendorAddresses rpt15 = new rptVendorAddresses();
rpt15.SetDataSource(_reportData);
rptMain.ReportSource = rpt15;
break;
case "PackingSlip":
rptPackingSlip rpt16 = new rptPackingSlip();
rpt16.SetDataSource(_reportData);
rptMain.ReportSource = rpt16;
break;
case "Invoice":
rptInvoice rpt17 = new rptInvoice();
rpt17.SetDataSource(_reportData);

rptMain.ReportSource = rpt17;
break;
case "PO":
rptPurchaseOrder rpt18 = new rptPurchaseOrder();
rpt18.SetDataSource(_reportData);
rptMain.ReportSource = rpt18;
break;
case "Quote":
rptQuote rpt19 = new rptQuote();
rpt19.SetDataSource(_reportData);
rptMain.ReportSource = rpt19;
break;

}


 
First of all, thank you very much for your response. Also, I must apologize for the fact that I am a newbie in C#. I see you point that attempting to set a viewer object to a form is not going to work. However, this is my dilemma; from my main form (Form1.cs), I need to click a button (called Display) to load and view my crviewer form that I created in my Design view with Crystal Report tool drawn in the form (csForm.cs). Your first three bullet points above, I have already accomplished. What I have been unsuccessful in is calling and displaying my viewer form (csForm.cs) from within the main form (Form1.cs). Thx.
 
Sorry I did not update this thread. This was my solotion:
try
{
// Initialized my form viewer
display_myform.csForm crViewer1 = new csForm();
// Load report, datasources, other stuff and display...
crViewer1.Show();
}
// if any exception, catch it...
catch (Exception ex)
{
statusBar1.Text = "Error: " + ex.Message.ToString();
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top