Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. VB.net - WPF - Help with treeview

VB.net - WPF - Help with treeview

Scheduled Pinned Locked Moved WPF
csharpwpfhelpwinforms
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lasse Frederiksen
    wrote on last edited by
    #1

    I am new to VB.net and WPF. and i need some help. When i select a item in the combobox. then i will have that Directory i have selected in the combobox. add to the listbox or treeview (as a treeview with folders/subfolders/... and files) edit: My problem is i apparently can't use .Nodes in my VB.net code. And my events (afterselected) is useless.. I can use it in VB.net(winforms) but not as WPF (Class Library)

    Imports System.Windows
    Imports System.Windows.Controls
    Imports System.Windows.Data
    Imports System.Windows.Input

    Public Class VerticalPaneExample
    Dim root = "c:\temp\"
    Dim matroot As String = ""
    Dim newtoolsti As String = ""
    Dim enodetext As String = ""

    Private Sub VerticalPaneExample\_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
        Dim folders() As String = IO.Directory.GetDirectories(root)
        For Each folder As String In folders
            Dim clean As String
            clean = folder.Replace(root, "")
            Me.matpicker.Items.Add(clean)
        Next
    End Sub
    
    Private Sub matpicker\_AfterSelect(sender As Object, e As RoutedEventArgs) Handles matpicker.AfterSelect
        Me.matpicker.SelectedItem = matroot
    
        For Each direct As String In System.IO.Directory.GetDirectories(matroot)
            Dim dir As String = System.IO.Path.GetFileNameWithoutExtension(direct)
            Dim newNode = viewptffiles.Nodes.Add(dir, dir)
            RecurseChildFolders(direct, newNode)
            Try
                For Each file As String In System.IO.Directory.GetFiles(direct, "\*.\*")
                    newNode.Nodes.Add(System.IO.Path.GetFileName(file))
                Next
            Catch ex As Exception
            End Try
        Next
    
    Private Sub RecurseChildFolders(directory As String, parent As TreeNode)
        For Each direct As String In System.IO.Directory.GetDirectories(directory)
            Dim dir As String = System.IO.Path.GetFileNameWithoutExtension(direct)
            Dim child = parent.Nodes.Add(dir, dir)
            RecurseChildFolders(direct, child)
            Try
                For Each file As String In System.IO.Directory.GetFiles(direct, "\*.\*")
                    child.Nodes.Add(System.IO.Path.GetFileName(file))
                Next
            Catch ex As Exception
            End Try
        Next
    End Sub
    

    End Class

    My xaml file look like this:

    R 1 Reply Last reply
    0
    • L Lasse Frederiksen

      I am new to VB.net and WPF. and i need some help. When i select a item in the combobox. then i will have that Directory i have selected in the combobox. add to the listbox or treeview (as a treeview with folders/subfolders/... and files) edit: My problem is i apparently can't use .Nodes in my VB.net code. And my events (afterselected) is useless.. I can use it in VB.net(winforms) but not as WPF (Class Library)

      Imports System.Windows
      Imports System.Windows.Controls
      Imports System.Windows.Data
      Imports System.Windows.Input

      Public Class VerticalPaneExample
      Dim root = "c:\temp\"
      Dim matroot As String = ""
      Dim newtoolsti As String = ""
      Dim enodetext As String = ""

      Private Sub VerticalPaneExample\_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
          Dim folders() As String = IO.Directory.GetDirectories(root)
          For Each folder As String In folders
              Dim clean As String
              clean = folder.Replace(root, "")
              Me.matpicker.Items.Add(clean)
          Next
      End Sub
      
      Private Sub matpicker\_AfterSelect(sender As Object, e As RoutedEventArgs) Handles matpicker.AfterSelect
          Me.matpicker.SelectedItem = matroot
      
          For Each direct As String In System.IO.Directory.GetDirectories(matroot)
              Dim dir As String = System.IO.Path.GetFileNameWithoutExtension(direct)
              Dim newNode = viewptffiles.Nodes.Add(dir, dir)
              RecurseChildFolders(direct, newNode)
              Try
                  For Each file As String In System.IO.Directory.GetFiles(direct, "\*.\*")
                      newNode.Nodes.Add(System.IO.Path.GetFileName(file))
                  Next
              Catch ex As Exception
              End Try
          Next
      
      Private Sub RecurseChildFolders(directory As String, parent As TreeNode)
          For Each direct As String In System.IO.Directory.GetDirectories(directory)
              Dim dir As String = System.IO.Path.GetFileNameWithoutExtension(direct)
              Dim child = parent.Nodes.Add(dir, dir)
              RecurseChildFolders(direct, child)
              Try
                  For Each file As String In System.IO.Directory.GetFiles(direct, "\*.\*")
                      child.Nodes.Add(System.IO.Path.GetFileName(file))
                  Next
              Catch ex As Exception
              End Try
          Next
      End Sub
      

      End Class

      My xaml file look like this:

      R Offline
      R Offline
      Richard Deeming
      wrote on last edited by
      #2

      You've told us what you want to do, and shown your code, but you forgot to tell us what the problem is or where you're stuck.


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      L 1 Reply Last reply
      0
      • R Richard Deeming

        You've told us what you want to do, and shown your code, but you forgot to tell us what the problem is or where you're stuck.


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        L Offline
        L Offline
        Lasse Frederiksen
        wrote on last edited by
        #3

        Sorry.. My problem is i apparently can't use .Nodes in my VB.net code. And my events (afterselected) is useless.. I can use it in VB.net(winforms) but not as WPF (Class Library)

        R 1 Reply Last reply
        0
        • L Lasse Frederiksen

          Sorry.. My problem is i apparently can't use .Nodes in my VB.net code. And my events (afterselected) is useless.. I can use it in VB.net(winforms) but not as WPF (Class Library)

          R Offline
          R Offline
          Richard Deeming
          wrote on last edited by
          #4

          Your WPF code is using a ListBox, not a tree-view control. TreeView, data binding and multiple templates - The complete WPF tutorial[^] TreeView Overview - WPF .NET Framework | Microsoft Docs[^] How to: Create Simple or Complex TreeViews - WPF .NET Framework | Microsoft Docs[^]


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups