Glossary Item Box
ActiveReports allows you to use scripting to permit reports saved to an XML file to contain code. By including scripting when the RPX files are saved into XML, the reports later can be loaded, run and displayed directly to the viewer control without needing to use the designer.
This walkthrough illustrates how to use scripting when creating a subreport.
This walkthrough is split up into the following activities:
To complete the walkthrough, you must have access to the NorthWind database (NWind.mdb).
When you have finished this walkthrough, you will have a report that looks similar to the following.
To add two ActiveReports to a Visual Studio project
To connect the subreport to a data source
To add controls to rptMain
Control | DataField | Name | Text/Caption | Section | Location |
---|---|---|---|---|---|
TextBox | CompanyName | txtCompanyName | Company Name | ghCompanies | 0, 0 |
TextBox | OrderDate | txtOrderDate | Order Date | ghOrders | 1, 0 |
TextBox | RequiredDate | txtRequiredDate | Required Date | ghOrders | 3.5, 0 |
TextBox | ShippedDate | txtShippedDate | Shipped Date | ghOrders | 5.5, 0 |
Label | (Empty string) | lblOrderDate | Ordered: | ghOrders | 0, 0 |
Label | (Empty string) | lblRequiredDate | Required: | ghOrders | 2.5, 0 |
Label | (Empty string) | lblShippedDate | Shipped: | ghOrders | 4.5, 0 |
Subreport | (Empty string) | Subreport1 | (Empty string) | Detail | 0, 0 |
To add controls to rptSub
Control | Name | Text/Caption | Location |
---|---|---|---|
Label | lblUnitPrice | Unit Price | 4.375, 0 |
Label | lblDiscount | Discount | 5.5, 0 |
Label | lblProductName | Product Name | 0, 0 |
Label | lblQuantity | Quantity | 3.25, 0 |
Line | Line | (Empty string) | X1 = 3.2
Y1 = 0 X2 = 3.2 Y2 = 0.2 |
Line | Line1 | (Empty string) | X1 = 4.3
Y1 = 0 X2 = 4.3 Y2 = 0.2 |
Line | Line2 | (Empty string) | X1 = 5.5
Y1 = 0 X2 = 5.5 Y2 = 0.2 |
Line | Line3 | (Empty string) | X1 = 0
Y1 = 0.2 X2 = 6.5 Y2 = 0.2 |
Control | DataField | Name | Text/Caption | Misc Details | Location |
---|---|---|---|---|---|
TextBox | ProductName | txtProductName | Product Name | (Empty string) | 0, 0 |
TextBox | Quantity | txtQuantity | Quantity | (Empty string) | 3.25, 0 |
TextBox | order details.UnitPrice | txtUnitPrice | Unit Price | OutputFormat = Currency | 4.375, 0 |
TextBox | Discount | txtDiscount | Discount | OutputFormat = Currency | 5.5, 0 |
Line | (Empty string) | Line4 | (Empty string) | (Empty string) | X1 = 3.2
Y1 = 0 X2 = 3.2 Y2 = 0.2 |
Line | (Empty string) | Line5 | (Empty string) | (Empty string) | X1 = 4.3
Y1 = 0 X2 = 4.3 Y2 = 0.2 |
Line | (Empty string) | Line6 | (Empty string) | (Empty string) | X1 = 5.5
Y1 = 0 X2 = 5.5 Y2 = 0.2 |
Line | (Empty string) | Line7 | (Empty string) | (Empty string) | X1 = 0
Y1 = 0.2 X2 = 6.5 Y2 = 0.2 |
To add scripting to the report
The following example shows what the scripting code looks like.
//C#
private string getDatabasePath()
{
Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.LocalMachine;
regKey = regKey.CreateSubKey("SOFTWARE\\Data Dynamics\\ActiveReports for .NET 2.0\\SampleDB");
return (string)regKey.GetValue("");
}
public void ActiveReport_ReportStart()
{
string m_dbPath = getDatabasePath();
string m_cnnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + m_dbPath + "\\NWind.MDB";
string sqlString = "Select * from orders inner join customers on orders.customerid = customers.customerid order by CompanyName, OrderDate";
DataDynamics.ActiveReports.DataSources.OleDBDataSource m_ds = new DataDynamics .ActiveReports.DataSources.OleDBDataSource();
m_ds.ConnectionString = m_cnnString;
m_ds.SQL = sqlString;
rpt.DataSource = m_ds;
}
public void Detail_Format()
{
DataDynamics.ActiveReports.ActiveReport rptSub = new DataDynamics.ActiveReports .ActiveReport();
rptSub.LoadLayout(System.Windows.Forms.Application.StartupPath + @"..\..\" + ((SubReport)rpt.Sections["Detail"].Controls["SubReport"]) .ReportName);
((SubReport)rpt.Sections["Detail"].Controls["SubReport"]).Report = rptSub;
}
To add scripting to the report
The following example shows what the scripting code looks like.
//C#
int cnt;
public void Detail_Format()
{
cnt++;
if(cnt % 2 == 0)
{
rpt.Sections["Detail"].BackColor = System.Drawing.Color.White;
}
else
{
rpt.Sections["Detail"].BackColor = System.Drawing.Color .BlanchedAlmond;
}
}
To view the report
See Also |
Samples | Walkthroughs | Scripting
Copyright © 2004-2005 Data Dynamics, Ltd. All rights reserved.