Results 1 to 13 of 13

Thread: ucShellTree get checked items

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2011
    Posts
    500

    ucShellTree get checked items

    Hi. I have set the treeview to show checkboxes. But how do i loop through each one to show what is selected.

    tks

  2. #2
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,714

    Re: ucShellTree get checked items

    There's the .CheckedPaths property that returns a Variant array of fully qualified paths to each checked item.

    Note that if you selected a Library, it will return the .library-ms file, which you'd have to query for the paths included in the library, see here.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2011
    Posts
    500

    Re: ucShellTree get checked items

    Quote Originally Posted by fafalone View Post
    There's the .CheckedPaths property that returns a Variant array of fully qualified paths to each checked item.

    Note that if you selected a Library, it will return the .library-ms file, which you'd have to query for the paths included in the library, see here.
    Had a chance to try the checked paths. However it does not work as expected.
    If i use the code below and select a top level folder and set it so that all the sub folders and files are selected, i only get the top folder only returned as a path.
    If i then expand the top folder to show other folders and files, if i deselect a folder checkbox and leave some other folders & files slected, i get the same top folder only.

    Now if i de select all files & folders and then re tick them and run the code below. It works as expected.

    It seems that the checkbox selection is not being propergated correctley when selecting a top folder.

    Code:
     Dim mFiles() As String
    
        mFiles = ucShellTree1.CheckedPaths
    
        Dim x As Integer
        For x = 0 To UBound(mFiles)
    
            Debug.Print mFiles(x)
        Next x
    so after a bit of experimenting , if the top folder is expanded and then clicking the top folder checkbox , then each sub folder & file is selected.
    If i run code above it will show only sub folders (but not contents) & files.
    I would think that if i select a top folder checkbox then running the above code should show all sub folders & files within.

    I assume therefore i would need to check to see if the selected checkbox is a folder or a file.

    How would i go about selecting a top folder and then showing a complete list of all subfolders & files.

    tks
    Last edited by k_zeon; Aug 17th, 2022 at 02:32 PM.

  4. #4
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,714

    Re: ucShellTree get checked items

    I'm really having trouble following here.

    I did identify an issue; it's not registering partial checks as unchecked when autocheck = true and exclusionchecks=false. Besides that I'm not seeing any mismatch between what the tree is showing and what checkedpaths reports.

    See if this fixes it... in the WndProc (last function in the module), in the TVN_ITEMCHANGEDW block, the bolded branch should be added to the block at the bottom:

    Code:
                    If (nmtvic.uStateNew And TVIS_STATEIMAGEMASK) = &H1000 Then
                        TVEntries(nmtvic.lParam).Checked = False
                        TVEntries(nmtvic.lParam).Excluded = False
                    ElseIf (nmtvic.uStateNew And TVIS_STATEIMAGEMASK) = &H2000 Then
                        DebugAppend "ItemCheck"
                        TVEntries(nmtvic.lParam).Checked = True
                        TVEntries(nmtvic.lParam).Excluded = False
                    ElseIf ((nmtvic.uStateNew And TVIS_STATEIMAGEMASK) = &H3000) And (mAutocheck = True) Then
                        TVEntries(nmtvic.lParam).Checked = False
                        If mExCheckboxes Then
                            TVEntries(nmtvic.lParam).Excluded = True
                        End If
                    ElseIf ((nmtvic.uStateNew And TVIS_STATEIMAGEMASK) = &H3000) And (mAutocheck = False) Then
                        DebugAppend "ItemExclude"
                        TVEntries(nmtvic.lParam).Checked = False
                        TVEntries(nmtvic.lParam).Excluded = True
                    ElseIf (nmtvic.uStateNew And TVIS_STATEIMAGEMASK) = &H4000 Then
                        TVEntries(nmtvic.lParam).Checked = False
                        TVEntries(nmtvic.lParam).Excluded = True
                    End If

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2011
    Posts
    500

    Re: ucShellTree get checked items

    Quote Originally Posted by fafalone View Post
    I'm really having trouble following here.

    I did identify an issue; it's not registering partial checks as unchecked when autocheck = true and exclusionchecks=false. Besides that I'm not seeing any mismatch between what the tree is showing and what checkedpaths reports.

    See if this fixes it... in the WndProc (last function in the module), in the TVN_ITEMCHANGEDW block, the bolded branch should be added to the block at the bottom:

    Code:
                    If (nmtvic.uStateNew And TVIS_STATEIMAGEMASK) = &H1000 Then
                        TVEntries(nmtvic.lParam).Checked = False
                        TVEntries(nmtvic.lParam).Excluded = False
                    ElseIf (nmtvic.uStateNew And TVIS_STATEIMAGEMASK) = &H2000 Then
                        DebugAppend "ItemCheck"
                        TVEntries(nmtvic.lParam).Checked = True
                        TVEntries(nmtvic.lParam).Excluded = False
                    ElseIf ((nmtvic.uStateNew And TVIS_STATEIMAGEMASK) = &H3000) And (mAutocheck = True) Then
                        TVEntries(nmtvic.lParam).Checked = False
                        If mExCheckboxes Then
                            TVEntries(nmtvic.lParam).Excluded = True
                        End If
                    ElseIf ((nmtvic.uStateNew And TVIS_STATEIMAGEMASK) = &H3000) And (mAutocheck = False) Then
                        DebugAppend "ItemExclude"
                        TVEntries(nmtvic.lParam).Checked = False
                        TVEntries(nmtvic.lParam).Excluded = True
                    ElseIf (nmtvic.uStateNew And TVIS_STATEIMAGEMASK) = &H4000 Then
                        TVEntries(nmtvic.lParam).Checked = False
                        TVEntries(nmtvic.lParam).Excluded = True
                    End If
    I will give this a try tonight when i get in.

    just to try to explain.

    place the ShellTree on a form , add a button and add code from post 3. enable checkboxes
    run the app in ide.
    now expand drive C: and check a folder.

    Now click the button and only the folder is returned ie C:\Test ( but anything below this folder is not shown)

    Now unselect this folder and then expand the folder to see the folders & files below.

    Now select the same folder as before and click the button. I now see the list of Sub folders and files returned in the list.
    But, i only see the next level of folders

    I think it may be that if the folder is not expanded and you select that folder then just that folder is returned.
    If expanded then the folders being displayed & files are returned in a list.

    hope that explains it a bit better

  6. #6
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,714

    Re: ucShellTree get checked items

    Oh right but that matches what the tree shows as checked, right?

    Open C
    Check C:\A
    (list, only C:\A)
    Uncheck C:\A
    Expand C:\A
    Check C:\A
    (list, C:\A, C:A\Sub1, C:\A\Sub2, C:\A\Sub3, etc)

    Yes in that circumstance, it will check all the subitems, and the parent and children will be returned in the list. Is this what you're describing? If so, this is as-intended.

    But are you saying you're getting files returned even though you're not showing files? If so I can't reproduce that... I don't know where it would get them, it doesn't even load the files unless ShowFiles is True. Or is ShowFiles True and they're not showing up?

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2011
    Posts
    500

    Re: ucShellTree get checked items

    Quote Originally Posted by fafalone View Post
    Oh right but that matches what the tree shows as checked, right?

    Open C
    Check C:\A
    (list, only C:\A)
    Uncheck C:\A
    Expand C:\A
    Check C:\A
    (list, C:\A, C:A\Sub1, C:\A\Sub2, C:\A\Sub3, etc)

    Yes in that circumstance, it will check all the subitems, and the parent and children will be returned in the list. Is this what you're describing? If so, this is as-intended.

    But are you saying you're getting files returned even though you're not showing files? If so I can't reproduce that... I don't know where it would get them, it doesn't even load the files unless ShowFiles is True. Or is ShowFiles True and they're not showing up?
    Hi fafalone. yes that is correct. As you described above. I want to include Folders & also Files. (yes i have ShowFiles and this works fine)

    Just a note. If i expand C: and show sub folders & files and then check C:\A , it only lists C:\A, but if you expand the A folder , the sub folders and files are also checked.
    but will not return in the list

    I am making a backup app and need to select Folders & files to back up.

    One thing i tried was to Select C:\A while not expanded, lists C:\A . all ok...
    I then expand folder A and see Sub Folder B & Sub Folder C checkboxes selected as well as File z.pic (example)

    if i uncheck sub Folder B and run the code again, it still just shows C:\A. I need to uncheck C:\A and run again before Folder C & File z.pic get returned.

    is there anyway to return a complete list of all sub folders & files by selecting a top folder.? maybe a setting

    maybe PM me and i can make a small video to show what i mean. tks

  8. #8
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,714

    Re: ucShellTree get checked items

    I can't seem to replicate this; I have ShowFiles = True now and, since fixing the partial check not excluded bug anyway, I can't produce a situation where there's a mismatch between what's visibly checked and what's listed.

    I expanded it while checked, the subfolders and subfiles were checked, and they were all returned. Same if I expanded and unchecked then checked.

    I guess what I could do is redesign how it enumerates checked items. Have it do it by walking the treeview and checking each item state, then returning the corresponding path if checked.

    Is AutoCheck True or False?

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2011
    Posts
    500

    Re: ucShellTree get checked items

    Quote Originally Posted by fafalone View Post
    I can't seem to replicate this; I have ShowFiles = True now and, since fixing the partial check not excluded bug anyway, I can't produce a situation where there's a mismatch between what's visibly checked and what's listed.

    I expanded it while checked, the subfolders and subfiles were checked, and they were all returned. Same if I expanded and unchecked then checked.

    I guess what I could do is redesign how it enumerates checked items. Have it do it by walking the treeview and checking each item state, then returning the corresponding path if checked.

    Is AutoCheck True or False?
    Auto check = True

    and
    yes to walking the treeview and checking each item state. would be good

    tks
    Last edited by k_zeon; Aug 18th, 2022 at 02:46 PM.

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2011
    Posts
    500

    Re: ucShellTree get checked items

    Hi fafalone.
    not sure you got my last message as i have no record of it being sent.


    I have linked 3 images. see details below where i have tried to explain

    https://www.dropbox.com/s/2vv78jhrnw...mage1.jpg?dl=0

    https://www.dropbox.com/s/n5e16nhv6p...mage2.jpg?dl=0

    https://www.dropbox.com/s/zbt63atgls...mage3.jpg?dl=0


    1. Open H: and select Test folder then press button. Returns H:\Test. ok good.
    2. Only expand Test folder and press button. Still only Returns H:\Test , Not good.
    3. Leave Test Expanded but deselect & reselect and press button. ok, good, but i would think that all sub folders and files should be returned as i have selected a top folder.
    then i get returned H:\Test , H:\Test\test.txt , H:\Test\Test2

    So if i select a top folder , then all sub folders or files within that folder are selected.
    If I then unselect Test2 Sub folder , the Test top folder then gets a square in the check box to show that not all sub folders or files are selected. this is ok.

    p.s

    as a side issue, the border style cannot be changed. when i do change it and run or re open the form it reverts back to Normal.
    Last edited by k_zeon; Aug 19th, 2022 at 11:34 AM.

  11. #11
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,714

    Re: ucShellTree get checked items

    This will fix all bugs related to .CheckedPaths not matching the display by syncing the item data with the tree data before reporting it... replace SetCheckedList with this version and the new sync function it calls:

    Code:
    Private Sub SyncChecks()
    'There's some bugs with item values but not visuals.
    Dim i As Long
    Dim uState As Long
    For i = 0 To UBound(TVEntries)
        If TVEntries(i).bDeleted = False Then
            uState = 0&
            uState = TreeView_GetItemState(hTVD, TVEntries(i).hNode, TVIS_STATEIMAGEMASK)
            If (uState And TVIS_STATEIMAGEMASK) = &H1000 Then  'Unchecked
                TVEntries(i).Checked = False
                TVEntries(i).Excluded = False
            ElseIf (uState And TVIS_STATEIMAGEMASK) = &H2000 Then 'Checked
                TVEntries(i).Checked = True
                TVEntries(i).Excluded = False
            ElseIf (uState And TVIS_STATEIMAGEMASK) = &H3000 Then 'Partially checked (only subitems are checked)
                TVEntries(i).Checked = False
                TVEntries(i).Excluded = False
            ElseIf (uState And TVIS_STATEIMAGEMASK) = &H4000 Then 'Exclusion checkmark
                TVEntries(i).Checked = False
                TVEntries(i).Excluded = True
            End If
         End If
    Next i
    End Sub
    Private Sub SetCheckedList()
    ReDim gPaths(0)
    nPaths = 0
    SyncChecks
    Dim i As Long
    For i = 0 To UBound(TVEntries)
        If (TVEntries(i).Checked = True) And (TVEntries(i).bDeleted = False) Then
            ReDim Preserve gPaths(nPaths)
            gPaths(nPaths) = TVEntries(i).sFullPath
            nPaths = nPaths + 1
        End If
    Next i
    End Sub

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2011
    Posts
    500

    Re: ucShellTree get checked items

    Quote Originally Posted by fafalone View Post
    This will fix all bugs related to .CheckedPaths not matching the display by syncing the item data with the tree data before reporting it... replace SetCheckedList with this version and the new sync function it calls:

    Code:
    Private Sub SyncChecks()
    'There's some bugs with item values but not visuals.
    Dim i As Long
    Dim uState As Long
    For i = 0 To UBound(TVEntries)
        If TVEntries(i).bDeleted = False Then
            uState = 0&
            uState = TreeView_GetItemState(hTVD, TVEntries(i).hNode, TVIS_STATEIMAGEMASK)
            If (uState And TVIS_STATEIMAGEMASK) = &H1000 Then  'Unchecked
                TVEntries(i).Checked = False
                TVEntries(i).Excluded = False
            ElseIf (uState And TVIS_STATEIMAGEMASK) = &H2000 Then 'Checked
                TVEntries(i).Checked = True
                TVEntries(i).Excluded = False
            ElseIf (uState And TVIS_STATEIMAGEMASK) = &H3000 Then 'Partially checked (only subitems are checked)
                TVEntries(i).Checked = False
                TVEntries(i).Excluded = False
            ElseIf (uState And TVIS_STATEIMAGEMASK) = &H4000 Then 'Exclusion checkmark
                TVEntries(i).Checked = False
                TVEntries(i).Excluded = True
            End If
         End If
    Next i
    End Sub
    Private Sub SetCheckedList()
    ReDim gPaths(0)
    nPaths = 0
    SyncChecks
    Dim i As Long
    For i = 0 To UBound(TVEntries)
        If (TVEntries(i).Checked = True) And (TVEntries(i).bDeleted = False) Then
            ReDim Preserve gPaths(nPaths)
            gPaths(nPaths) = TVEntries(i).sFullPath
            nPaths = nPaths + 1
        End If
    Next i
    End Sub
    tks. that seems to have fixed the issues i was having.

    maybe you can help with something else. I would like to select Folders & Files etc as a backup app

    going by previous examples ie H:\Test , if I expand H: to show the folder Test , the return would be H:\Test. I would then save this path in a settings file which tells my app to backup everything within.

    But if i do the same as above, but expand the folder Test to show the sub folders & files etc and then press the button , i get

    H:\Test
    H:\Test\test.txt
    H:\Test\Test2

    How would i tell my app what to back up, as i H:\Test\test.txt & H:\Test\Test2 already has the top folder H:\Test selected. As if i backup H:\Test then there is no need to backup the other 2 as they are already in H:\Test

    Is there some way to test if H:\Test\test.txt & H:\Test\Test2 is a Child of H:\Test , if they are then i can exclude them from my settings file

    something like

    If ucShellTree1.path("H:\Test\test.txt").isChild or some other way to check.

    or how to test which folder is the top folder.

    H:\ would be a drive
    H:\Test would be a Top folder
    H:\Test\Test1 would be a child folder
    H:\Test\test.txt would be a child file

    something like this
    Last edited by k_zeon; Aug 19th, 2022 at 03:56 PM.

  13. #13
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,714

    Re: ucShellTree get checked items

    Seems like this problem would be far easier solved with a PathFileExists check. When you're making the backup, if you've already backed up H:\Test, any child is going to come back 'Already exists', in which case you'd skip it (or you can query times/sizes if you're overwriting).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width