Using ActiveReports Professional Edition, you can set up a custom end-user report designer. This walkthrough illustrates how to set up a basic end-user report designer on a Windows form. (The Designer control is not supported on the Web.)
Note: The Designer control requires the .NET Framework full profile version. To ensure you are using the full profile version, go to the Visual Studio Project Properties, then to the Compile tab, Advanced Compile Options... (for Visual Basic projects) or to the Application tab (for C# projects) and in the Target framework field select a full profile version. |
This walkthrough is split up into the following activities:
When you have finished this walkthrough, you will have a working end-user report designer that looks like the following.
Note: If you need help with adding the Designer controls to your Visual Studio toolbox, see Adding ActiveReports Controls. |
Controls for the form
Control | Parent | Name | Dock | Miscellaneous |
---|---|---|---|---|
ToolStripContainer | formDesigner | ToolStripContainer1 | Fill | LeftToolStripPanel Enabled = False; RightToolStripPanel Enabled = False |
SplitContainer | ToolStripContainer1 | SplitContainer1 | Fill | |
StatusStrip | ToolStripContainer1 BottomToolStripPanel | arStatus | ||
Designer | SplitContainer1 Panel2 | arDesigner | None | Anchor = Top, Bottom, Left, Right; Resize and move as necessary. |
ReportExplorer | SplitContainer1 Panel2 | arReportExplorer | None | ReportDesigner = arDesigner; Anchor = Top, Right; Resize and move as necessary. |
Toolbox | SplitContainer1 Panel1 | arToolbox | Fill | |
PropertyGrid | SplitContainer1 Panel2 | arPropertyGrid | None | Anchor = Top, Bottom, Right; Resize and move as necessary. |
The following examples show what the code looks like.
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste ABOVE the formDesigner class. |
Copy Code |
---|---|
'Visual Basic 'Add the following Imports statements Imports DataDynamics.ActiveReports Imports DataDynamics.ActiveReports.Design Imports DataDynamics.ActiveReports.Design.Toolbox |
To write the code in C#
C# code. Paste ABOVE the formDesigner class. |
Copy Code |
---|---|
//C# //Add the following using statements using DataDynamics.ActiveReports; using DataDynamics.ActiveReports.Design; using DataDynamics.ActiveReports.Design.Toolbox; |
The following examples show what the code looks like.
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the formDesigner class. |
Copy Code |
---|---|
'Visual Basic Private Sub OnExit(ByVal sender As Object, ByVal e As EventArgs) Close() End Sub |
To write the code in C#
C# code. Paste INSIDE the formDesigner class. |
Copy Code |
---|---|
//C# private void OnExit(object sender, EventArgs e) { Close(); } |
The following examples show what the code looks like.
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the formDesigner class. |
Copy Code |
---|---|
Private Sub LoadTools(ByVal arToolbox As DataDynamics.ActiveReports.Design.Toolbox.Toolbox) 'Add Data Providers Me.arToolbox.AddToolboxItem(New System.Drawing.Design.ToolboxItem(GetType(System.Data.DataSet)), "Data") Me.arToolbox.AddToolboxItem(New System.Drawing.Design.ToolboxItem(GetType(System.Data.DataView)), "Data") Me.arToolbox.AddToolboxItem(New System.Drawing.Design.ToolboxItem(GetType(System.Data.OleDb.OleDbConnection)), "Data") Me.arToolbox.AddToolboxItem(New System.Drawing.Design.ToolboxItem(GetType(System.Data.OleDb.OleDbDataAdapter)), "Data") Me.arToolbox.AddToolboxItem(New System.Drawing.Design.ToolboxItem(GetType(System.Data.Odbc.OdbcConnection)), "Data") Me.arToolbox.AddToolboxItem(New System.Drawing.Design.ToolboxItem(GetType(System.Data.Odbc.OdbcDataAdapter)), "Data") Me.arToolbox.AddToolboxItem(New System.Drawing.Design.ToolboxItem(GetType(System.Data.SqlClient.SqlConnection)), "Data") Me.arToolbox.AddToolboxItem(New System.Drawing.Design.ToolboxItem(GetType(System.Data.SqlClient.SqlDataAdapter)), "Data") End Sub |
To write the code in C#
C# code. Paste INSIDE the formDesigner class. |
Copy Code |
---|---|
private void LoadTools(DataDynamics.ActiveReports.Design.Toolbox.Toolbox arToolbox) { //Add Data Providers this.arToolbox.AddToolboxItem(new System.Drawing.Design.ToolboxItem(typeof(System.Data.DataSet)), "Data"); this.arToolbox.AddToolboxItem(new System.Drawing.Design.ToolboxItem(typeof(System.Data.DataView)), "Data"); this.arToolbox.AddToolboxItem(new System.Drawing.Design.ToolboxItem(typeof(System.Data.OleDb.OleDbConnection)), "Data"); this.arToolbox.AddToolboxItem(new System.Drawing.Design.ToolboxItem(typeof(System.Data.OleDb.OleDbDataAdapter)), "Data"); this.arToolbox.AddToolboxItem(new System.Drawing.Design.ToolboxItem(typeof(System.Data.Odbc.OdbcConnection)), "Data"); this.arToolbox.AddToolboxItem(new System.Drawing.Design.ToolboxItem(typeof(System.Data.Odbc.OdbcDataAdapter)), "Data"); this.arToolbox.AddToolboxItem(new System.Drawing.Design.ToolboxItem(typeof(System.Data.SqlClient.SqlConnection)), "Data"); this.arToolbox.AddToolboxItem(new System.Drawing.Design.ToolboxItem(typeof(System.Data.SqlClient.SqlDataAdapter)), "Data"); } |
The following examples show what the code for the method looks like.
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the formDesigner Load event. |
Copy Code |
---|---|
'Note: Assigning the ToolBox to the designer before calling NewReport ' automatically adds the default controls to the toolbox in a group called ' "ActiveReports 6" LoadTools(arToolbox) arDesigner.Toolbox = arToolbox ' Add Menu and ToolStrips to Form Dim menuStrip As ToolStrip = arDesigner.CreateToolStrips(DesignerToolStrips.Menu)(0) Dim fileMenu As ToolStripDropDownItem = CType(menuStrip.Items(0), ToolStripDropDownItem) ' Add an Exit command to the File menu fileMenu.DropDownItems.Add(New ToolStripMenuItem("Exit", DataDynamics.ActiveReports.Design.Images.Delete, AddressOf OnExit)) Dim panel As ToolStripPanel = ToolStripContainer1.TopToolStripPanel panel.Join(menuStrip, 0) panel.Join(arDesigner.CreateToolStrips(DesignerToolStrips.Zoom)(0), 1) panel.Join(arDesigner.CreateToolStrips(DesignerToolStrips.Undo)(0), 1) panel.Join(arDesigner.CreateToolStrips(DesignerToolStrips.Edit)(0), 1) panel.Join(arDesigner.CreateToolStrips(DesignerToolStrips.Report)(0), 1) panel.Join(arDesigner.CreateToolStrips(DesignerToolStrips.Layout)(0), 2) panel.Join(arDesigner.CreateToolStrips(DesignerToolStrips.Format)(0), 2) 'Set up the Status Bar Dim tsLabel1 As ToolStripStatusLabel = New ToolStripStatusLabel() tsLabel1.Spring = True tsLabel1.BorderStyle = Border3DStyle.Sunken arStatus.Items.Add(tsLabel1) |
To write the code in C#
C# code. Paste INSIDE the formDesigner Load event. |
Copy Code |
---|---|
//C# //Note: Assigning the ToolBox to the designer before calling NewReport // automatically adds the default controls to the toolbox in a group called // "ActiveReports 6" LoadTools(arToolbox); arDesigner.Toolbox = arToolbox; // Add Menu and CommandBar to Form ToolStrip menuStrip = arDesigner.CreateToolStrips(DesignerToolStrips.Menu)[0]; ToolStripDropDownItem fileMenu = (ToolStripDropDownItem)menuStrip.Items[0]; // Add an Exit command to the File menu fileMenu.DropDownItems.Add(new ToolStripMenuItem("Exit", DataDynamics.ActiveReports.Design.Images.Delete, OnExit)); ToolStripPanel panel = ToolStripContainer1.TopToolStripPanel; panel.Join(menuStrip, 0); panel.Join(arDesigner.CreateToolStrips(DesignerToolStrips.Zoom)[0], 1); panel.Join(arDesigner.CreateToolStrips(DesignerToolStrips.Undo)[0], 1); panel.Join(arDesigner.CreateToolStrips(DesignerToolStrips.Edit)[0], 1); panel.Join(arDesigner.CreateToolStrips(DesignerToolStrips.Report)[0], 1); panel.Join(arDesigner.CreateToolStrips(DesignerToolStrips.Layout)[0], 2); panel.Join(arDesigner.CreateToolStrips(DesignerToolStrips.Format)[0], 2); //Set up the Status Bar ToolStripStatusLabel tsLabel1 = new ToolStripStatusLabel(); tsLabel1.Spring = true; tsLabel1.BorderStyle = Border3DStyle.Sunken; arStatus.Items.Add(tsLabel1); |
The following examples show what the code to display objects in the status bar looks like.
To write the code in Visual Basic.NET
The following example shows what the code for the method looks like.
Visual Basic.NET code. Paste INSIDE the SelectionChanged event. |
Copy Code |
---|---|
'Display the current selection in the designer's status bar Dim curSelection As String = "" Dim selectionEnum As IEnumerator = Nothing If Not (arDesigner.Selection Is Nothing) Then selectionEnum = arDesigner.Selection.GetEnumerator() End If While Not (selectionEnum Is Nothing) AndAlso selectionEnum.MoveNext() If TypeOf selectionEnum.Current Is Section Then curSelection = curSelection + (CType(selectionEnum.Current, Section)).Name + ", " End If If TypeOf selectionEnum.Current Is ARControl Then curSelection = curSelection + (CType(selectionEnum.Current, ARControl)).Name + ", " End If If TypeOf selectionEnum.Current Is Field Then curSelection = curSelection + (CType(selectionEnum.Current, Field)).Name + ", " End If If TypeOf selectionEnum.Current Is Parameter Then curSelection = curSelection + (CType(selectionEnum.Current, Parameter)).Key + ", " End If If TypeOf selectionEnum.Current Is ActiveReport Then curSelection = curSelection + (CType(selectionEnum.Current, ActiveReport)).Document.Name + ", " End If End While If Me.arStatus.Created AndAlso Not (Me.arStatus.Items(0) Is Nothing) Then If Not (curSelection = "") Then Me.arStatus.Items(0).Text = "Current Selection: " + curSelection.Substring(0, curSelection.Length - 2) Else Me.arStatus.Items(0).Text = "No Selection" End If End If |
To write the code in C#
C# code. Paste INSIDE the SelectionChanged event. |
Copy Code |
---|---|
//C# //This will display the current selection in the designer's status bar string curSelection = ""; System.Collections.IEnumerator selectionEnum = null; if(arDesigner.Selection != null) selectionEnum = arDesigner.Selection.GetEnumerator(); while(selectionEnum != null && selectionEnum.MoveNext()) { if(selectionEnum.Current is Section) curSelection = curSelection + (selectionEnum.Current as Section).Name + ", "; if(selectionEnum.Current is ARControl) curSelection = curSelection + (selectionEnum.Current as ARControl).Name + ", "; if(selectionEnum.Current is Field) curSelection = curSelection + (selectionEnum.Current as Field).Name + ", "; if(selectionEnum.Current is Parameter) curSelection = curSelection + (selectionEnum.Current as Parameter).Key + ", "; if(selectionEnum.Current is ActiveReport) curSelection = curSelection + (selectionEnum.Current as ActiveReport).Document.Name + ", "; } if(this.arStatus.Created && this.arStatus.Items[0] != null) { if(curSelection != "") this.arStatus.Items[0].Text = "Current Selection: " + curSelection.Substring(0, curSelection.Length - 2); else this.arStatus.Items[0].Text = "No Selection"; } |