ok, so I have been at this awhile and I just can't seem to nail it down. The current code works fine on the very first fresh but after that it doesn't remember what node was clicked. For this refresh I am looking for a ini file and if found I delete the ini file and refresh the tree. The tree has only 2 parents and never anymore then that.
This first part is the timer sub
This next part is the search function.Code:Private Sub Timer2_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer2.Tick Dim SelectNode As String = Me.tvFolders.SelectedNode.Name Try ' check to see if file exist, if so do refresh then delete file If (File.Exists(appPath & "refresh.ini")) Then File.Delete(appPath & "refresh.ini") Me.Update() ' this clears icons, lvFiles.Items.Clear() FillTreeView() InitializeTimer() 'MsgBox("1 " & SelectNode) 'Me.tvFolders.SelectedNode = curNode If curNode.ToString.Length > 0 Then If objFS.SearchTree(SelectNode, tvFolders.Nodes("Parent1")) Then found = True ElseIf objFS.SearchTree(SelectNode, tvFolders.Nodes("Parent2")) Then found = True End If Else 'MsgBox("curnode is blank") Me.tvFolders.SelectedNode = tvFolders.Nodes("Jackson County") End If 'MsgBox(Me.tvFolders.SelectedNode) objFS.ListFoldersFiles(Me.tvFolders.SelectedNode.Tag, lvFiles, ImageList2) 'MsgBox(curNode.Text) Timer2.Enabled = False Cursor.Current = System.Windows.Forms.Cursors.Default ToolStripStatusLabel1.Text = "" Me.tvFolders.Focus() Else InitializeTimerRefresh() End If Catch ex As Exception Debug.WriteLine(ex.Message) MsgBox("Refresh Failed" & Chr(13) & Chr(13) & ex.Message, vbOKOnly, "Failed To Refresh Timer") End Try End Sub
Now the main problem is if you click on a child in parent2 and hit refresh it is not sending Parent2 as a treenode to the search function and it doesn't remember the node clicked. But if you click on a child in parent1 it remembers the node but always refreshes to the top parent1 node. but the very first time you refresh in parent1 it works perfect. I have a feeling my logic is messed up. Because even on the second refresh regardless of which parent you are in it never comes back with failed message from the search function.Code:Public Function SearchTree(ByVal sSearchString As String, ByVal startNode As TreeNode) As Boolean MsgBox("1 " & startNode.Name) MsgBox("2 " & sSearchString) If CBool(InStr(1, startNode.Name, sSearchString, vbTextCompare)) Then Form1.tvFolders.SelectedNode = startNode Return True End If For Each n As TreeNode In startNode.Nodes If SearchTree(sSearchString, n) Then found = True Exit For End If Next If found Then Return True Else MsgBox("Failed to find") Return False End If 'Return True 'lLastNodeFound = 0 End Function
Can somebody please point out what I might be doing wrong?




Reply With Quote