Things were going good, but now it seems when the treeview loads I get an error
Code:
System.NullReferenceException: Object reference not set to an instance of an object.
at AppWindow.Form1.tvFolders_AfterSelect(Object sender, TreeViewEventArgs e)
at System.Windows.Forms.TreeView.TvnSelected(NMTREEVIEW* nmtv)
at System.Windows.Forms.TreeView.WmNotify(Message& m)
at System.Windows.Forms.TreeView.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Here is the function
Code:
Private Sub tvFolders_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvFolders.AfterSelect
curNode = e.Node
Dim root1 As Boolean = False
Try
If curNode.Text = "Jackson County" Then
root1 = True
ElseIf curNode.Text = "Personal" Then
MnuFDelete.Enabled = False
lvFiles.Items.Clear()
Exit Sub
Else
curNode.Tag = appPath & curNode.Text & "\"
End If
If curNode.Tag.ToString.Length < 1 Then
MsgBox("appPath empty")
End If
If curNode.Level = 0 Then
curNode.ImageIndex = 2
curNode.SelectedImageIndex = 2
Else
curNode.ImageIndex = 0
curNode.SelectedImageIndex = 1
End If
If Not curNode.Text = "Personal" Then
' Find all the files in the currentlty selected directory
objFS.ListFoldersFiles(curNode.Tag, lvFiles, ImageList2)
End If
If My.Settings.Favorites.Contains(curNode.Text) Then
MnuFDelete.Enabled = True
If lvFiles.Items.Count < 1 Then
lvFiles.Items.Clear()
End If
Else
MnuFDelete.Enabled = False
End If
lvFiles.Sort()
lvFiles.Columns(0).AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent)
lvFiles.Columns(2).AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent)
Catch ex As Exception
Debug.WriteLine(ex.Message)
MsgBox("Select Failed" & Chr(13) & Chr(13) & ex.Message, vbOKOnly, "Failed To Select")
End Try
End Sub
But Jackson County is hard coded to always be there. I also set the curNode.Tag to Jackson County on form load. If Personal is not selected then it defaults to Jackson County. Like I said, I cannot get it in debug mode so I have placed stops at various places and I have stepped through it, never once got the error. I believe it is a timing issue from when the form loads to selecting the parent, all done without user intervention.
Private Sub tvFolders_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvFolders.AfterSelect
curNode = e.Node
Dim root1 As Boolean = False
Dim ErrorStr As String = Nothing
Try
ErrorStr = "start"
If curNode.Text = "Jackson County" Then
root1 = True
ErrorStr = ErrorStr & Chr(13) & "Root=true"
ElseIf curNode.Text = "Personal" Then
MnuFDelete.Enabled = False
ErrorStr = ErrorStr & Chr(13) & "Personal=true"
lvFiles.Items.Clear()
Exit Sub
Else
curNode.Tag = appPath & curNode.Text & "\"
End If
If curNode.Tag.ToString.Length < 1 Then
MsgBox("appPath empty")
End If
If curNode.Level = 0 Then
curNode.ImageIndex = 2
curNode.SelectedImageIndex = 2
ErrorStr = ErrorStr & Chr(13) & "level=0"
Else
curNode.ImageIndex = 0
curNode.SelectedImageIndex = 1
ErrorStr = ErrorStr & Chr(13) & "level > 0"
End If
If Not curNode.Text = "Personal" Then
' Find all the files in the currentlty selected directory
ErrorStr = ErrorStr & Chr(13) & "Get list folders= " & curNode.Tag
objFS.ListFoldersFiles(curNode.Tag, lvFiles, ImageList2)
End If
If My.Settings.Favorites.Contains(curNode.Text) Then
MnuFDelete.Enabled = True
ErrorStr = ErrorStr & Chr(13) & "node set in favorites"
If lvFiles.Items.Count < 1 Then
lvFiles.Items.Clear()
End If
Else
MnuFDelete.Enabled = False
ErrorStr = ErrorStr & Chr(13) & "node not in favorites"
End If
lvFiles.Sort()
lvFiles.Columns(0).AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent)
lvFiles.Columns(2).AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent)
Catch ex As Exception
Debug.WriteLine(ex.Message)
MsgBox("Select Failed" & Chr(13) & Chr(13) & ex.Message & Chr(13) & ErrorStr, vbOKOnly, "Failed To Select")
End Try
End Sub
Which I had added strings to each section. I got the error after many reboots. And you can see the error I get. Again, I cannot get it in the .NET studio. I am also having issue son that as well as I cannot test it in the studio as it conflicts with the application running on my current desktop. But thats another thread, lol
is there anyway to avoid selecting the default tree until after it loads? because it doesn't look like I am setting it any place. unless anybody has any idea where that error is coming from