Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8629745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:53:00+00:00 2026-06-12T08:53:00+00:00

I want to create a simple printer manager to use in our Terminal server

  • 0

I want to create a simple printer manager to use in our Terminal server environment. Because of GPO restrictions, there are limits of what built-in functionality I can use. So I decided to try to write my own simple GUI to do that.

Now, the printers are distributed in a folder, with subfolders to categorize them. In each folder there are .lnk files to the actual printer on the printserver.

What I want to do is to populate a treeview with the folders, and the printers in a listview, based on which item is clicked on the treeview.

I’ve already managed to search for directories and to search the files for each item I’ve clicked. But I realized, why not use a collection or similar to do this during the startup of the form? That way, it’ll be faster. Because right now, there’s a small delay each time I click an item in the treeview. Because it scans for files each time.

How can I add the same to a collection and use that instead?

Here’s my current code:

Public Sub populateTreeView(ByVal strPath As String)

        Dim di As New IO.DirectoryInfo(strPath)
        Dim diar1 As IO.DirectoryInfo() = di.GetDirectories()
        Dim dra As IO.DirectoryInfo

        For Each dra In diar1
            ImageList1.Images.Add(GetSmallIcon(dra.FullName))

            TreeView1.Nodes.Add("", dra.Name, nIndex)
            nIndex = nIndex + 1
        Next
    End Sub

    Private Sub TreeView1_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles TreeView1.AfterSelect
        ListView1.Clear()
        nIndex = 0

        Dim di As New IO.DirectoryInfo(strIniSettings & "\" & TreeView1.SelectedNode.Text)
        Dim diar1 As IO.FileInfo() = di.GetFiles()
        Dim dra As IO.FileInfo

        For Each dra In diar1
            Dim strName As String
            strName = Replace(dra.Name, ".lnk", "")
            ImageList2.Images.Add(GetLargeIcon(dra.FullName))

            ListView1.Items.Add("", strName, nIndex)
            nIndex = nIndex + 1
        Next
    End Sub

Notice the Imagelists? I also get the Icon for each item as well.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:53:03+00:00Added an answer on June 12, 2026 at 8:53 am

    Since your data is not complex, a simple LookUp may be the right collection for you (or just a plain Dictionary).

    Just query the printers once, and store it in a member variable, or just use the Tag property of the TreeNodes so store the file names.

    In the example below, I’m using a simple Linq query to create a LookUp where the Key is the directory name (you could also just use full path to the directory), and the items are the file names.

    You could then either query the collection by a given Key (the directory name), or use the Tag property.


    LINQPad example:

    Sub Main
    
        ' query printers once (just replace C:\test with your path)
        ' store the result in a member variable of your form
        Dim printer = new DirectoryInfo("C:\test").GetDirectories() _
                                                  .SelectMany(Function(d) d.GetFiles()) _
                                                  .ToLookup(Function(f) f.Directory.Name, Function(f) f.Name)
    
        ' Or, using a Dictionary
        ' Dim printer = new DirectoryInfo("C:\test").GetDirectories() _
        '                                           .ToDictionary(Function(d) d.Name, Function(d) d.GetFiles().Select(Function(f) f.Name).ToList())
    
    
    
        Dim l = new ListView() With {.Dock = DockStyle.Right}
        Dim t = new TreeView() With {.Dock = DockStyle.Left}                    
        AddHandler t.AfterSelect, Sub(s, e)
                                        ' This is your AfterSelect event handler
                                        ' The filenames are stored in the Tag of the TreeNode
                                        ' You could also use 'For Each p As String in printer(e.Node.Text)'
                                        l.Items.Clear()
                                        For Each p As String in e.Node.Tag
                                            Dim item = l.Items.Add(p.Replace(".lnk", ""))
                                            'TODO: Set Icon on item
                                        Next
                                  End Sub
    
        ' Populate TreeView once
        For Each folder in printer
            Dim fNode = t.Nodes.Add(folder.Key)
            'TODO: Set Icon on fNode
    
            ' store the files in the Tag of the node.
            ' You don't have to, but it will make it easier
            fNode.Tag = folder
        Next
    
        ' Show test form            
        Dim w = new Form()
        w.Controls.Add(t)
        w.Controls.Add(l)
        w.Show()
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a simple server application which runs on the desktop, and
I want to create a simple class that I can use and encode as
I want to create simple app able to edit images. Main view of app
JavaScript. I want to create simple script, that will be resize loaded image using
I want to create a simple app, where the user can take a photo.
I want to create a simple app that shows me the city of the
I want to create a simple Javascript program with a HTML interface. The program
I want to create a simple login functionality in WP7 app using remote MySQL
I want to create a simple bash script to launch a Java program on
I want to create a simple user registration form with First / Last name,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.