?
Solved

checkbox on a filelistbox in vb6

Posted on 2007-10-19
4
Medium Priority
?
801 Views
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.
0
Comment
Question by:samiam41
  • 2
4 Comments
 
LVL 6

Expert Comment

by:MELeBlanc
ID: 20110015
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
   
    lstFiles.Clear
    Set objFolder = fs.GetFolder("D:\test")
    For Each objFile In objFolder.Files
   
        lstFiles.AddItem objFile.Name
       
    Next
   
    'Clean up file objects
    Set objFolder = Nothing
    Set objFile = Nothing

- M

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

Expert Comment

by:jpaulino
ID: 20110059
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
Next

jpaulino
0
 
LVL 9

Author Comment

by:samiam41
ID: 20110202
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.
0
 
LVL 6

Accepted Solution

by:
MELeBlanc earned 2000 total points
ID: 20110603

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

-M
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Progress

807 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