HI,
How to retrieve data from UltraTreeview?
i tried the below code. It is not working 'due to 'Object reference not set to an instance' error.
' Declare variables for tree Dim CdTree As ITestDataTree Dim CdTreeNodes As ITestDataTreeNodes Dim CdTreeNode() As ITestDataTreeNode ' Variables to hold tree data CdTree = Tree2().GetTestData("TreeView") CdTreeNodes = CdTree.GetTreeNodes() - ----- "Error at this line 'Object reference not set to an instance of an object'" CdTreeNode = CdTreeNodes.GetRootNodes()
' Print out total number of nodes
MsgBox("Tree Total Node Count: " + CdTreeNodes.GetNodeCount())
MsgBox(
"Tree Root Node Count : " + CdTreeNodes.GetRootNodeCount())
' Iterate through tree branches; this is a recursive method. Dim I As Integer For I = 0 To CdTreeNode.Length - 1 ShowTree(CdTreeNode(I), 0) Next I
Thanks in advance. Rekha.
I am not sure what the indent and tabs objects are but you can do something like the following:
Public Function TestMain(ByVal args() As Object) As Object
Dim MyTree As Infragistics.RFT.NetTestObjects.UltraTreeTestObject = UltraTree1Tree()
Dim CdTree As ITestDataTree Dim CdTreeNodes As ITestDataTreeNodes Dim CdTreeNode() As ITestDataTreeNode ' Variables to hold tree data CdTree = MyTree.GetTestData("all tree data") CdTreeNodes = CdTree.GetTreeNodes() CdTreeNode = CdTreeNodes.GetRootNodes()
' Print out total number of nodes MsgBox("Tree Total Node Count: " + CdTreeNodes.GetNodeCount().ToString()) MsgBox("Tree Root Node Count : " + CdTreeNodes.GetRootNodeCount().ToString())
' loop through the tree root bands
Dim I As Integer For I = 0 To CdTreeNode.Length - 1 MsgBox(CdTreeNode(I).GetNode().ToString()) ShowTree(CdTreeNode(I), 0) LogInfo(CdTreeNode(I).GetNode().ToString()) Next I Return Nothing End Function
Public Sub ShowTree(ByVal Node As ITestDataTreeNode, ByVal ByVal_Indent As Integer) Dim CdTreeNodes As ITestDataTreeNode() CdTreeNodes = Node.GetChildren()
Dim I As Integer For I = 0 To CdTreeNodes.Length - 1 MsgBox(CdTreeNodes(I).GetNode().ToString()) ShowTree(CdTreeNodes(I), 0) LogInfo(CdTreeNodes(I).GetNode().ToString()) Next I End Sub
Hi Ammar,
Here we have child nodes as shown in the attached file. so i called showTree() method:
Public Sub ShowTree(ByVal Node As ITestDataTreeNode, ByVal_Indent As Integer)
IIf(Indent < Tabs.Length(), TabCount = Indent, TabCount = Tabs.Length())
Dim Children() As ITestDataTreeNode = Node.GetChildren()
Dim ChildCount As Integer
IIf(ChildCount <> 0, ChildCount = Children.Length, ChildCount = 0)
For I = 0 To ChildCount - 1 Next
ShowTree(Children(I), Indent + 1)
End Sub
But i'm unable to get the child data. and in childcount it is returning 0 which is wrong.
Rekha.
Hi Rekha,
Try this code: (if you want to iterate through all nodes recursively then you need to implement the "ShowTree" recursive method)
Dim CdTree As ITestDataTree
Dim CdTreeNodes As ITestDataTreeNodes
Dim CdTreeNode() As ITestDataTreeNode
' Variables to hold tree data
CdTree = Tree2().GetTestData("all tree data")
CdTreeNodes = CdTree.GetTreeNodes()
CdTreeNode = CdTreeNodes.GetRootNodes()
MsgBox("Tree Total Node Count: " + CdTreeNodes.GetNodeCount().ToString())
MsgBox("Tree Root Node Count : " + CdTreeNodes.GetRootNodeCount().ToString())
Dim I As Integer
For I = 0 To CdTreeNode.Length - 1
LogInfo(CdTreeNode(I).GetNode().ToString())
Next I
Regards,
Ammar