1.

Solve : vb.net treeview help?

Answer»

hi all,

I'm trying to create a explorer type treeview which shows all the drives on the machine and all the folders within them as CHILD objects.

the problem I have is that I seem to be unable to create a child object for a node that I've already created.



PRIVATE Sub tv1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles tv1.GotFocus

'makes 'my computer' start node and sets up for child nodes to be added below
With tv1.Nodes.Add("My Computer").Nodes


'for each computer drive avaiable, LIST as a child under my computer
For Each drive_info As System.IO.DriveInfo In System.IO.DriveInfo.GetDrives()


'add child nodes to my computer, drives. c, d, e, etc...
drive = drive_info.Name
.Add(drive)


'maybe a for each loop here, for each folder that exists in the drive, add child node



Next drive_info


End With

End Sub




Also, I have to select the treeview before it DISPLAYS any of my infomation. what can i REPLACE the tv1_GotFocus with so it displays as soon as the app is run.

cheers in advance
Try zeroing on which parent you're referring to. (yes I know there is only one). The snippet does not rely on the With you wrote.

Code: [Select]'for each computer drive avaiable, list as a child under my computer
For Each drive_info As System.IO.DriveInfo In System.IO.DriveInfo.GetDrives()
'add child nodes to my computer, drives. c, d, e, etc...
drive = drive_info.Name
tv1.SelectedNode.Nodes.Add(drive)
Next

Quote

Also, I have to select the treeview before it displays any of my infomation. what can i replace the tv1_GotFocus with so it displays as soon as the app is run.

Any chance you can put your logic in the Form_Load event? Both the TreeView and the Form have scores of events to choose from.


Discussion

No Comment Found