How do I tie a cmbBox that selects all drives (local and network) into a treeNode VB

Posted by jpavlov on Stack Overflow See other posts from Stack Overflow or by jpavlov
Published on 2010-06-15T14:19:35Z Indexed on 2010/06/15 14:22 UTC
Read the original article Hit count: 239

Filed under:
|

How do i tie in a selected item from a cmbBox with a treeView? I am looking to just obtain the value of the one selected drive Thanks.

Imports System Imports System.IO Imports System.IO.File

Imports System.Windows.Forms

Public Class F_Treeview_Demo

Private Sub F_Treeview_Demo_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    ' Initialize the local directory treeview


    Dim nodeText As String = ""
    Dim sb As New C_StringBuilder
    With My.Computer.FileSystem
        'Read in the number of drives
        For i As Integer = 0 To .Drives.Count - 1

            '** Build the drive's node text
            sb.ClearText()
            sb.AppendText(.Drives(i).Name)
            cmbDrives.Items.Add(sb.FullText)

        Next
    End With

    ListRootNodes()

End Sub

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
    Application.Exit()
End Sub

Private Sub tvwLocalFolders_AfterSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) _
                                        Handles tvwLocalFolders.AfterSelect
    ' Display the path for the selected node
    Dim folder As String = tvwLocalFolders.SelectedNode.Tag


    lblLocalPath.Text = folder

    ListView1.Items.Clear()
    Dim childNode As TreeNode = e.Node.FirstNode
    Dim parentPath As String = AddChar(e.Node.Tag)






End Sub

Private Sub AddToList(ByVal nodes As TreeNodeCollection)
    For Each node As TreeNode In nodes
        If node.Checked Then
            ListView1.Items.Add(node.Text)
            ListView1.Items.Add(Chr(13))
            AddToList(node.Nodes)





        End If
    Next
End Sub



Private Sub tvwLocalFolders_BeforeExpand(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) _
                                         Handles tvwLocalFolders.BeforeExpand

    ' Display the path for the selected node
    lblLocalPath.Text = e.Node.Tag
    ' Populate all child nodes below the selected node
    Dim parentPath As String = AddChar(e.Node.Tag)
    tvwLocalFolders.BeginUpdate()

    Dim childNode As TreeNode = e.Node.FirstNode
    'this i added
    Dim smallNode As TreeNode = e.Node.FirstNode

    Do While childNode IsNot Nothing
        ListLocalSubFolders(childNode, parentPath & childNode.Text)
        childNode = childNode.NextNode
        ''this i added
        ListLocalFiles(smallNode, parentPath & smallNode.Text)

    Loop
    tvwLocalFolders.EndUpdate()
    tvwLocalFolders.Refresh()
    ' Select the node being expanded
    tvwLocalFolders.SelectedNode = e.Node

    ListView1.Items.Clear()
    AddToList(tvwLocalFolders.Nodes)
    ListView1.Items.Add(Environment.NewLine)
End Sub
Private Sub ListRootNodes()
    ' Add all local drives to the Local treeview

    Dim nodeText As String = ""
    Dim sb As New C_StringBuilder
    With My.Computer.FileSystem
        For i As Integer = 0 To .Drives.Count - 1

            '** Build the drive's node text
            sb.ClearText()
            sb.AppendText(.Drives(i).Name)
            nodeText = sb.FullText
            nodeText = Me.cmbDrives.SelectedItem

            '** Add the drive to the treeview
            Dim driveNode As TreeNode
            driveNode = tvwLocalFolders.Nodes.Add(nodeText)
            'driveNode.Tag = .Drives(i).Name

            '** Add the next level of subfolders
            'ListLocalSubFolders(driveNode, .Drives(i).Name)
            ListLocalSubFolders(driveNode, nodeText)
            'driveNode = Nothing

        Next
    End With
End Sub

Private Sub ListLocalFiles(ByVal ParentNode As TreeNode, ByVal PParentPath As String)

    Dim FileNode As String = ""
    Try
        For Each FileNode In Directory.GetFiles(PParentPath)

            Dim smallNode As TreeNode
            smallNode = ParentNode.Nodes.Add(FilenameFromPath(FileNode))
            With smallNode
                .ImageIndex = 0
                .SelectedImageIndex = 1
                .Tag = FileNode
            End With
            smallNode = Nothing
        Next
    Catch ex As Exception
    End Try

End Sub

Private Sub ListLocalSubFolders(ByVal ParentNode As TreeNode, _
                                ByVal ParentPath As String)
    ' Add all local subfolders below the passed Local treeview node
    Dim FolderNode As String = ""
    Try
        For Each FolderNode In Directory.GetDirectories(ParentPath)
            Dim childNode As TreeNode
            childNode = ParentNode.Nodes.Add(FilenameFromPath(FolderNode))
            With childNode
                .ImageIndex = 0
                .SelectedImageIndex = 1
                .Tag = FolderNode
            End With
            childNode = Nothing
        Next
    Catch ex As Exception
    End Try

End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbDrives.SelectedIndexChanged

End Sub

Private Sub lblLocalPath_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblLocalPath.Click

End Sub

Private Sub grpLocalFileSystem_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles grpLocalFileSystem.Enter

End Sub

Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
    ' lbl1.Text = 

End Sub

Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged

End Sub

End Class

© Stack Overflow or respective owner

Related posts about vb

Related posts about treeview