This walkthrough builds on the steps completed in the previous walkthrough, Creating the Basic Layout for an End-User Report Designer, and is split up into the following activities:
- Adding a Reference to the ToolBoxClassLib DLL
- Adding Imports/using statements
- Adding code to the formDesigner_Load event to set the designer's toolbox, set the designer's CommandBarManager, add an Exit command to the CommandBarManager, and set up the status bar.
- Adding code to create a data toolbox group
- Adding code to enable shortcut keys to work with the CommandBarManager
- Adding code to create the arDesigner_SelectionChanged event to display the current object selection in the status bar
- Adding code to close the End-User Report Designer when the Exit command is clicked on the File menu
When you have finished this walkthrough, you will have a working end-user report designer that looks like the following.
Adding a Reference to the ToolBoxClassLib DLL
To add the reference
- In the Solution Explorer, right-click on the References folder.
- In the Add Reference dialog, click the Browse button. For Visual Studio 2005, select the "Browse" tab.
- Navigate to the directory that contains the samples and select \Samples\CSharp\Professional\EndUserDesigner. If you are developing with VB.NET, select \Samples\VB\Professional\EndUserDesigner.
- Select DataDynamics.ActiveReports.ToolBoxClassLib.dll and click OK.
Adding this reference exposes DataDynamics' packaged ToolBoxService. If you wish to further customize the ToolBox, you can access the source files at ActiveReports for .NET 3.0\Samples\ToolBoxClassLib in the directory at which your samples are installed. No support is provided for such customization. |
Adding Imports/using statements
To add the statements
To write the code in Visual Basic or C#
- Right-click in any section of formDesigner, and click on View Code to display the code view for the Windows Form. Add the following Imports/using statements.
The following example shows what the code looks like.
'Visual Basic 'Add the following Imports statements Imports DataDynamics.ActiveReports Imports DataDynamics.ActiveReports.Design Imports DataDynamics.ActiveReports.Design.Toolbox //C# //Add the following using statements using DataDynamics.ActiveReports; using DataDynamics.ActiveReports.Design; using DataDynamics.ActiveReports.Design.Toolbox;
Adding code to the formDesigner_Load event
To write the code in Visual Basic or C#
- Double-click the title bar of the formDesigner. This creates an event-handling method for the formDesigner_Load event. Add code to the handler to:
- Set up the toolbox
- Set the designer's CommandBarManager
- Add an Exit command to the CommandBarManager
- Set up the designer's status bar for Visual Studio for .NET 2003 and the
The following example shows what the code for the method looks like.
'Visual Basic Private arToolbox As Toolbox Private commandBarManager As CommandBarManager Private Sub formDesigner_Load(ByVal sender As Object, ByVal e As System.EventArgs) 'Set up the toolbox Me.arToolbox = New DataDynamics.ActiveReports.Design.Toolbox.Toolbox Me.arToolbox.Dock = System.Windows.Forms.DockStyle.Fill 'Add the toolbox to pnlToolbox Me.pnlToolbox.Controls.Add(Me.arToolbox) 'Assign the toolbox to the designer to give functionality and add default controls Me.arDesigner.Toolbox = Me.arToolbox 'Fill Toolbox with a data group LoadTools(Me.arToolbox) 'Set the CommandBarManager of arDesigner to commandBarManager commandBarManager = Me.arDesigner.CommandBarManager Me.Controls.Add(commandBarManager) 'Add an Exit command to the File menu of the first command bar of the CommandBarManager Dim menu As CommandBarMenu = CType(Me.commandBarManager.CommandBars(0).Items(0), CommandBarMenu) menu.Items.AddSeparator() menu.Items.AddButton("Exit", AddressOf OnExit, 0) 'Set up the status bar Me.arStatus.Panels.Add(New StatusBarPanel) Me.arStatus.Panels.Add(New StatusBarPanel) Me.arStatus.Panels(0).AutoSize = StatusBarPanelAutoSize.Spring Me.arStatus.Panels(1).AutoSize = StatusBarPanelAutoSize.Spring Me.arStatus.ShowPanels = True End Sub //C# private Toolbox arToolbox; private CommandBarManager commandBarManager; private void formDesigner_Load(object sender, System.EventArgs e) { //Set up the toolbox this.arToolbox = new DataDynamics.ActiveReports.Design.Toolbox.Toolbox(); this.arToolbox.Dock = System.Windows.Forms.DockStyle.Fill; //Add the toolbox to pnlToolbox to give functionality and add default controls this.pnlToolbox.Controls.Add(this.arToolbox); //Assign the toolbox to the designer this.arDesigner.Toolbox = this.arToolbox; //Fill Toolbox with a data group LoadTools(this.arToolbox); //Add the CommandBarManager commandBarManager = this.arDesigner.CommandBarManager; this.Controls.Add(commandBarManager); // Add an exit command to the File menu of the first command bar of the CommandBarManager CommandBarMenu menu = this.commandBarManager.CommandBars[0].Items[0] as CommandBarMenu; menu.Items.AddSeparator(); menu.Items.AddButton("Exit", new CommandEventHandler(OnExit), 0); //Set up the Status Bar for Visual Studio for .NET 2003 this.arStatus.Panels.Add(new StatusBarPanel()); this.arStatus.Panels.Add(new StatusBarPanel()); this.arStatus.Panels[0].AutoSize = StatusBarPanelAutoSize.Spring; this.arStatus.Panels[1].AutoSize = StatusBarPanelAutoSize.Spring; this.arStatus.ShowPanels = true; }
Adding code to create a data toolbox group
To write the code in Visual Basic or C#
- Add the following code right after the Form_Load event to create a data group on the toolbox.
The following example shows what the code looks like.
'Visual Basic 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 //C# 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"); }
Adding code to enable shortcut keys to work with the CommandBarManager
To write the code in Visual Basic or C#
- Right-click in any section of formDesigner, and click on View Code to display the code view for formDesigner. Add the following code.
The following example shows what the code looks like.
'Visual Basic Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean If Me.arDesigner.Focused Then If Me.arDesigner.CommandBarManager.PreProcessMessage(msg) Then Return True End If End If Return MyBase.ProcessCmdKey(msg, keyData) End Function //C# protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if(this.arDesigner.CommandBarManager.PreProcessMessage(ref msg)) return true; return base.ProcessCmdKey(ref msg, keyData); }
Adding code to the arDesigner_SelectionChanged event
To write the code in Visual Basic
- Right-click in any section of formDesigner, and click on View Code to display the code view for the Windows Form. At the top left of the code view for formDesigner, click the drop-down arrow and select arDesigner. At the top right of the code window, click the drop-down arrow and select SelectionChanged. This creates an event-handling method for the arDesigner_SelectionChanged event.
To write the code in C#
- Click in the designer window of formDesigner to select arDesigner. Click on the events icon in the Properties window to display available events for the section. Double-click SelectionChanged. This creates an event-handling method for the arDesigner_SelectionChanged event.
The following example shows what the code for the method looks like.
'Visual Basic 'This will display the current selection in the designer's status bar Private Sub arDesigner_SelectionChanged() Handles arDesigner.SelectionChanged 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 ActiveReport3 Then curSelection = curSelection + (CType(selectionEnum.Current, ActiveReport3)).Document.Name + ", " End If End While If Me.arStatus.Created AndAlso Not (Me.arStatus.Panels(1) Is Nothing) Then If Not (curSelection = "") Then Me.arStatus.Panels(1).Text = "Current Selection: " + curSelection.Substring(0, curSelection.Length - 2) Else Me.arStatus.Panels(1).Text = "No Selection" End If End If End Sub //C# //This will display the current selection in the designer's status bar private void arDesigner_SelectionChanged() { string curSelection = ""; 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 ActiveReport3) curSelection = curSelection + (selectionEnum.Current as ActiveReport3).Document.Name + ", "; } if(this.arStatus.Created && this.arStatus.Panels[1] != null) { if(curSelection != "") this.arStatus.Panels[1].Text = "Current Selection: " + curSelection.Substring(0, curSelection.Length - 2); else this.arStatus.Panels[1].Text = "No Selection"; } }
Adding code to close the End-User Report Designer when the Exit command is clicked on the File menu
To write the code in Visual Basic
- Right-click in any section of formDesigner, and click on View Code to display the code view for the Windows Form. Add the following code.
To write the code in C#
- Right-click in any section of formDesigner, and click on View Code to display the code view for the Windows Form. Add the following code.
The following example shows what the code looks like.
'Visual Basic Private Sub OnExit(ByVal sender As Object, ByVal e As CommandEventArgs) Me.Close() End Sub //C# private void OnExit(object sender, CommandEventArgs e) { this.Close(); }