ActiveReports allows you to drop a third party control onto a report where it is recognized as a custom control. You can access its properties using type casting. In this case, we use hidden textboxes to populate a Visual Studio TreeView control.
Tip: To access properties of a custom control, you should use type casting (for the samples of code, see To access the TreeView control properties in code and assign data section below). |
SQL Query |
Copy Code |
---|---|
SELECT * FROM Orders ORDER BY ShipCountry, ShipCity, CustomerID, EmployeeID |
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 |
To write the code in C#
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; } |
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 ctlTreeView = CType(Me.CustomControl1.Control, TreeView) 'create a tree node Dim objCountryTreeNode As TreeNode 'assign the text from a hidden textbox to the node objCountryTreeNode = AddNodeToTreeView(ctlTreeView.Nodes, Me.txtShipCountry1.Text) 'add a second-level node AddNodeToTreeView(objCountryTreeNode.Nodes, Me.txtShipCity1.Text) 'expand the top-level node so the second-level node is in view objCountryTreeNode.Expand() 'create a second top-level node Dim objCustomerTreeNode As TreeNode objCustomerTreeNode = AddNodeToTreeView(ctlTreeView.Nodes, Me.txtCustomerID1.Text) AddNodeToTreeView(objCustomerTreeNode.Nodes, Me.txtEmployeeID1.Text) objCustomerTreeNode.Expand() |
To write the code in C#
C# code. Paste INSIDE the Detail Format event. |
Copy Code |
---|---|
//type cast the custom control as a TreeView ctlTreeView = (TreeView)this.CustomControl1.Control; //create a tree node TreeNode objCountryTreeNode; //assign the text from a hidden textbox to the node objCountryTreeNode = AddNodeToTreeView(ctlTreeView.Nodes, this.txtShipCountry1.Text); //add a second-level node AddNodeToTreeView(objCountryTreeNode.Nodes, this.txtShipCity1.Text); //expand the top-level node so the second-level node is in view objCountryTreeNode.Expand(); //create a second top-level node TreeNode objCustomerTreeNode; objCustomerTreeNode = AddNodeToTreeView(ctlTreeView.Nodes, this.txtCustomerID1.Text); AddNodeToTreeView(objCustomerTreeNode.Nodes, this.txtEmployeeID1.Text); objCustomerTreeNode.Expand(); |