Greetings,
I have been playing with, and researching, this all day and can't figure it out. I have a Windows Explorer style form with a TreeView and a ListView. I've populated the TreeView with directories and when a node is selected, the ListView fills with the contents of the directory associated with that node. No problem there, but I want to be able to select a directory in the ListView and automatically select the associated node in the TreeView, just like it works in Windows Explorer. All the information I've found online tells me how to populate the ListView from the TreeView, but I haven't found any good examples of how to populate the TreeView from the ListView.
I've been playing with this idea:
But when I select the directory in the ListView I get an "Index is outside the bounds of the array" error.
Any suggestions would be greatly appreciated.
Thanks!
I have been playing with, and researching, this all day and can't figure it out. I have a Windows Explorer style form with a TreeView and a ListView. I've populated the TreeView with directories and when a node is selected, the ListView fills with the contents of the directory associated with that node. No problem there, but I want to be able to select a directory in the ListView and automatically select the associated node in the TreeView, just like it works in Windows Explorer. All the information I've found online tells me how to populate the ListView from the TreeView, but I haven't found any good examples of how to populate the TreeView from the ListView.
I've been playing with this idea:
VB.NET:
Private Sub lstDirectoryInfo_ItemSelectionChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.ListViewItemSelectionChangedEventArgs) Handles lstDirectoryInfo.ItemSelectionChanged
' lstDirectoryInfo is the ListView
' treeFolders is the TreeView
For Each File As ListViewItem In lstDirectoryInfo.Items
If File.Selected = True Then
If File.SubItems(1).Text = "Directory" Then
'select that directory in tree view
treeFolders.SelectedNode = treeFolders.Nodes.Find(File.Text, True)(0)
End If
End If
Next
End Sub
But when I select the directory in the ListView I get an "Index is outside the bounds of the array" error.
Any suggestions would be greatly appreciated.
Thanks!
Last edited: