In a section report, ActiveReports Developer allows you to drop a third party control onto the report design surface where it is recognized as a custom control. You can access its properties using type casting.
In the following steps, we use hidden textbox controls to populate a Visual Studio TreeView control. These steps assume that you have already added a Section Report (code-based) template in a Visual Studio project. See Adding an ActiveReport to a Project for more information.
To add the TreeView control to a report
- From the Visual Studio toolbox Common Controls tab, drag and drop a TreeView control onto the detail section of a report.
- Notice that in the Properties window, the control is called CustomControl1.
To add data and hidden TextBox controls to the report
- Connect the report to the sample Nwind.mdb. The following steps use the Orders table from the NWind database. By default, in ActiveReports, the Nwind.mdb file is located at [User Documents folder]\ComponentOne Samples\ActiveReports Developer 7\Data\Nwind.mdb.
- From the Report Explorer, drag and drop the following fields onto the detail section of the report:
- ShipCountry
- ShipCity
- CustomerID
- EmployeeID
- On the design surface, select all four TextBox controls, and in the Properties window, change their Visible property to False.
To create a function to add nodes to the TreeView control
- Right-click the design surface and select View Code to see the code view for the report.
- Add the following code inside the report class to add a function to the report for adding nodes to the TreeView control.
The following examples show what the code for the function looks like.
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the report class. | Copy Code |
---|---|
Private Function AddNodeToTreeView(ByVal colNodes As TreeNodeCollection, ByVal sText As String) As TreeNode Dim objTreeNode As TreeNode objTreeNode = New TreeNode(sText) colNodes.Add(objTreeNode) Return objTreeNode End Function |
C# code. Paste INSIDE the report class. | Copy Code |
---|---|
private TreeNode AddNodeToTreeView(TreeNodeCollection colNodes, string sText) { TreeNode objTreeNode; objTreeNode = new TreeNode(sText); colNodes.Add(objTreeNode); return objTreeNode; } |
To access the TreeView control properties in code and assign data
- On the report design surface, double-click the detail section to create an event-handling method for the Detail_Format event.
- Add the following code to the handler to access the TreeView properties and assign data from the hidden TextBox controls.
The following example shows what the code for the method looks like.
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the Detail Format event. | Copy Code |
---|---|
'Type cast the custom control as a TreeView 'Create a tree node 'Create a second top-level node |
C# code. Paste INSIDE the Detail Format event. | Copy Code |
---|---|
//Type cast the custom control as a TreeView |