Losing positions on items in TreeView
I have a current problem selecting items in a treeview. Basically I need to iterate through each item in the tree view, perform an action then move on to the next. In the latest release of our software, the position in the treeview is lost once you have carried out a particular action and the script will then randomly jump to a different item.
I need to go through each one in sequential order. Does anyone know the best way to store the position so that when I specify Item/Click it will go to the correct item?
I tried getting the position before the action is performed by getting the selected node- nodeName = TreeView.wSelection
.Then after the action is performed -Call TreeView.ClickItem(nodeName) to take it back to the correct position but this doesn;t seem to work. Below is the code:
Sub RunResultSetReportsNewFrom(Items, TreeView)
If (Items.Count-1) mod 2 = 0 Then
totalCount = (Items.Count-1) * 2
Else
totalCount = ((Items.Count-1) * 2) -1
End if
For i = 0 To totalCount
originalResultSet= False
Log.Enabled = True
Set Item = Items.Item(i)
foundRS = False
Item.DblClick
nodeName = TreeView.wSelection
Log.Enabled = False
'Do a New from
If (cash.adminForm.VariableDefinitionForm.ResultSetForm.pnlMain.pnlResultSetEditor.resultSetEditor1.resultSetNameAndLocationEditor1.WaitAliasChild("txtNewName", 1000).Exists) Then
resultSetNameTemp = resultSetName.wText
If Instr(resultSetNameTemp, "Auto") Then
originalResultSet= False
Else
originalResultSet= True
End if
closeResultSetBtn.ClickButton
End if
If originalResultSet= True Then
foundRS =True
Call Item.ClickR
Call cash.cmuResultSetTreeView.Click(50, 41)
Call resultSetName.SetText(resultSetNameTemp & "Auto")
'calculate the ResultSets
calculateResultSetBtn.ClickButton
calculationStartTime = Now()
While Not (cash.dlgResultSetCalculationResult.WaitAliasChild("btnOK", 1000).Exists)
aqUtils.Delay 5000 ' 5 sec delay
Wend
calculationEndTime = Now()
totalCalculationTime =DateDiff("s",calculationStartTime,calculationEndTime)
Call Log.Message("Total time taken in seconds to run the ResultSet calculation for : " & resultSetToCalculate & " is : " & totalCalculationTime)
calculateSuccessMsgBtn.ClickButton
'retrieve the name of the ResultSet or folder
Log.Enabled = True
Call Log.Message("ResultSet" & resultSetNameTemp)
Else
foundRS = False
End If
Log.Enabled = False
' Expand the item
Call treeView.ClickItem(nodeName)
If foundRS = False Then
Item.Click
Item.Expand
End if
' Expand child items
If Not (Item.Items Is Nothing) Then
Call RunResultSetReportsNewFrom(Item.Items, TreeView)
End If
Next
End Sub
The problem seems to occur at the end -after the calculation has taken place i.e.
Call treeView.ClickItem(nodeName)
If foundRS = False Then
Item.Click
Item.Expand
End if
' Expand child items
If Not (Item.Items Is Nothing) Then
Call RunResultSetReportsNewFrom(Item.Items, TreeView)
End If
Next
I need to make sure that it goes to the correct item again.
Thanks in advance!
Joanne