checkbox on a filelistbox in vb6

Posted on 2007-10-19
Last Modified: 2012-08-13
I am trying to write a vb6 program that will allow a user to select multiple check boxes in order to open multiple .pdf documents. I can use the file listbox but I want to put checkboxes on it for the user to choose or have the option to choose all of the files. I am not sure if this is possible any help will be greatly appreciated.
Question by:samiam41
    LVL 6

    Expert Comment

    I don't think it is possible to create a filelistbox with checkboxes on it.. but you could create one with a regular listbox and some file system object coding...

    Here are the basics... simply add the listbox control, flip its property to include checkboxes, probably change so that it can have multiple selections.. then the following code will populate it.

        Dim fs        As New Scripting.FileSystemObject
        Dim objFolder As Folder
        Dim objFile   As File
        Set objFolder = fs.GetFolder("D:\test")
        For Each objFile In objFolder.Files
            lstFiles.AddItem objFile.Name
        'Clean up file objects
        Set objFolder = Nothing
        Set objFile = Nothing

    - M

    .. Also.. Don't forget to add a reference to the Microsoft Scripting Runtime!
    LVL 48

    Expert Comment

    I always like to use the listview. You can set the checkboxes to true and the View to List

    On form load add the pdf names (full path)

    ListView1.ListItens.Add ,,"c:\abc.pdf"
    ListView1.ListItens.Add ,,"c:\def.pdf"
    ListView1.ListItens.Add ,,"c:\ghi.pdf"

    Then to open the selected items

    Dim item As ListItem

    For Each item In ListView1.ListItems
      If item.Checked then
        Shell item.Text
      End If

    LVL 9

    Author Comment

    Thanks MELeBlanc that works great, however do you have a small routine that i can open wit ha button either one at a time or all if user selects all. The multiselect will not allow me to set it if I use the checkbox.
    LVL 6

    Accepted Solution


    I don't have dev environment right in front of me... so this may not be exact...

    dim idx as integer

    for idx = 0 to lstfiles.listcount - 1
       lstfiles.selected(idx) = true
    next idx


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
    Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now