dcsimg
Results 1 to 9 of 9

Thread: Compare 2 treeviews child items

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2019
    Posts
    142

    Compare 2 treeviews child items



    .dat is loaded in treeview1.
    Local zip files are loaded into treeview2.

    How do i compare treeview1 and treeview2 parent and child items.
    Treeview2 parent item may not exist in treeview1 some times so change image index value.
    Treeview2 if one or more are not found then change image index

    is this the right way of doing it,i se my icons change green but is it comparing the child and parent
    Code:
    rivate Sub Command5_Click()
        Dim NodX As Node, NodX2 As Node
                   For Each NodX In TreeView1.Nodes
                    For Each NodX2 In TreeView2.Nodes
                      If NodX.Text = NodX2.Text Then
                        'NodX.Selected = True
    
      NodX2.Image = 4
                      End If
                  Next
                  Next
    End Sub
    Last edited by doberman2002; Oct 16th, 2019 at 04:45 AM.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Aug 2019
    Posts
    142

    Re: Compare 2 treeviews child items



    Code:
    Private Sub Command9_Click()
     Dim NodX As Node, NodX1 As Node
        Dim lNod As Node, lNod1 As Node
        
     For Each NodX1 In TreeView1.Nodes
            For Each NodX In TreeView2.Nodes
                If NodX1.Text = NodX.Text Then
    NodX1.Image = 4
    NodX.Image = 4
                End If
            Next
            Next
    End Sub
    Code:
    NodX.Image = 4
    green
    NodX.Image = 3
    red
    if all dont match then parant icon
    Code:
    NodX.Image = 2
    if all match then parant icon
    Code:
    NodX.Image = 4
    if all or few dont match then
    Code:
    NodX.Image = 2

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,525

    Re: Compare 2 treeviews child items

    My guess is that they are green because they exist elsewhere in your treeview, like under a different root node.

    I think I would try to compare the node's FullPath instead of its text. The FullPath property should be more unique for what you are attempting.

    Edited & Tip: If you find a match, exit that inner loop with "Exit For". There is no need to keep looping thru TreeView2 after a match is found.
    Last edited by LaVolpe; Oct 16th, 2019 at 08:44 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Aug 2019
    Posts
    142

    Re: Compare 2 treeviews child items

    Quote Originally Posted by LaVolpe View Post
    My guess is that they are green because they exist elsewhere in your treeview, like under a different root node.

    I think I would try to compare the node's FullPath instead of its text. The FullPath property should be more unique for what you are attempting.

    Edited & Tip: If you find a match, exit that inner loop with "Exit For". There is no need to keep looping thru TreeView2 after a match is found.
    do i scan each zip contents comparing it with .dat.
    here is a code that reads zip contents i found.

    Code:
    Dim oShellApp As New Shell32.Shell
        Dim ZipFileName As String, oFile
        ZipFileName = App.Path & "\1943kai.zip"
        For Each oFile In oShellApp.NameSpace(ZipFileName).Items
            'Debug.Print (oFile.Type)
            'Debug.Print (oFile.ModifyDate)
            'Debug.Print (oFile.IsFileSystem)
            'Debug.Print (oFile.IsFolder)
            'Debug.Print (oFile.Path)
            'Debug.Print (oFile.Size)
    
        Next
    do i use a loop on treeview1 and this and match it

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,525

    Re: Compare 2 treeviews child items

    Maybe a misunderstanding... FullPath is a property of each treeview node.
    Code:
    Debug.Print Treeview1.Node(1).FullPath
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Aug 2019
    Posts
    142

    Re: Compare 2 treeviews child items

    Quote Originally Posted by LaVolpe View Post
    Maybe a misunderstanding... FullPath is a property of each treeview node.
    Code:
    Debug.Print Treeview1.Node(1).FullPath
    Code:
    Dim I As Integer, x As Integer
    Dim NodX As Node, NodX2 As Node
        Dim lNod As Node, lNod1 As Node
            
    
     For Each NodX In TreeView2.Nodes
     x = NodX.Index
    Debug.Print TreeView2.Nodes(x).FullPath
            Next
    Code:
    1943.zip\1943.01
    1943.zip\1943.02
    1943.zip\1943.03
    1943b.zip
    1943b.zip\bm03.14d
    1943b.zip\bm02.13d
    1943ja.zip
    1943ja.zip\bm01.12d
    1943ja.zip\bm02.13d
    1943ja.zip\bm03.14d
    1943kai.zip
    1943kai.zip\bmprom.04
    1943kai.zip\bmprom.06
    1943kai.zip\1943kai.02
    1943kai.zip\1943kai.03
    1943kai.zip\1943kai.05
    1943kai.zip\1943kai.04
    1943kai.zip\1943kai.06
    1943kai.zip\1943kai.07
    1943kai.zip\1943kai.08
    1943kai.zip\1943kai.09
    1943kai.zip\bmk01.bin
    1943kai.zip\1943kai.10
    1943kai.zip\bmk10.bin
    1943kai.zip\1943kai.11
    1943kai.zip\bmk11.bin
    1943kai.zip\bmk12.bin
    1943kai.zip\1943kai.13
    1943kai.zip\1943kai.14
    1943kai.zip\1943kai.15
    1943kai.zip\1943kai.16
    1943kai.zip\1943kai.17
    1943kai.zip\1943kai.18
    1943kai.zip\1943kai.19
    1943kai.zip\bmk02.bin
    1943kai.zip\1943kai.20
    1943kai.zip\1943kai.21
    1943kai.zip\1943kai.22
    1943kai.zip\1943kai.23
    1943kai.zip\1943kai.24
    1943kai.zip\1943kai.25
    1943kai.zip\bmk03.bin
    1943kai.zip\bmk05.bin
    1943kai.zip\bmk07.bin
    1943kai.zip\bmk08.bin
    1943kai.zip\bmk09.bin
    1944.zip
    1944.zip\nff.01
    1944.zip\nff.04
    1944.zip\nff.11
    1944.zip\nff.12
    1944.zip\nff.13
    1944.zip\nff.14
    1944.zip\nff.15
    1944.zip\nff.16
    1944.zip\nff.17
    1944.zip\nff.18
    1944.zip\nff.19
    1944.zip\nff.20
    1944.zip\nffu.03
    1944.zip\nffu.05
    1944d.zip
    1944d.zip\nffud.03
    Code:
    Dim FoundIt As Boolean, ii As Integer, ix As Integer
        Dim NodX As Node, NodX2 As Node
                   For Each NodX In TreeView1.Nodes
                    ix = NodX.Index
                    For Each NodX2 In TreeView2.Nodes
                      ii = NodX2.Index
                      If NodX.FullPath = NodX2.FullPath Then
    'TreeView2.Nodes(x).FullPath
                     
     FoundIt = True
    On Error Resume Next
    TreeView1.Nodes(ix).Image = 4
    TreeView2.Nodes(ii).Image = 4
    Exit For
                      End If
                  Next
                    If FoundIt Then
    
    
          Else
    
          End If
          FoundIt = False
                  Next
    There is a long freeze while it searches but does the job, like you said unique yes it works clean but that freeze tho lol.

    1 question, how will i code something like this.
    if all child green then parent green off course image=3 i will set it.
    if all not green then set title image=2 ' 2 is orange icon.
    Last edited by doberman2002; Oct 16th, 2019 at 11:18 AM.

  7. #7
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,525

    Re: Compare 2 treeviews child items

    Your search routine works by is very inefficient. You are comparing all nodes. But you only really need to compare the child nodes of matching parent nodes. If you rework this, you should get must faster results.

    One suggestion:
    1. Search the root nodes first, only comparing root nodes to root nodes -- don't include child nodes in the comparisons
    2. When a match is found, then compare only child nodes of the two root nodes

    For that type of searching/looping, you'll need to enumerate nodes using treeview node methods like .Next, .FirstSibling, etc. This is more complex to learn, but is usually far more efficient. You might find examples on this site.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Aug 2019
    Posts
    142

    Re: Compare 2 treeviews child items

    Quote Originally Posted by LaVolpe View Post
    But you only really need to compare the child nodes of matching parent nodes. If you rework this, you should get must faster results.
    Search the root nodes first, only comparing root nodes to root nodes -- don't include child nodes in the comparisons
    Correct this will also reduce waiting time excluding unwanted files to be searched right.

    Am still thinking how to search title with title and once matched execute search for child files.
    Am new to treeview not been using for ages.

    Only if i know where to start otherwise i would have done it,it is a must i have that option so its faster if you can help will be great full just so that i can Se and learn from to, you can take look at my code skills it is super noob y am still picking up slowly.

    Code:
    Dim I As Integer, x As Integer
    Dim NodX As Node, NodX2 As Node
        Dim lNod As Node, lNod1 As Node
            
    
     For Each NodX In TreeView2.Nodes
     x = NodX.Index
     If InStr(TreeView2.Nodes(x).Text, ".zip") Then
    Debug.Print TreeView2.Nodes(x).Text
    End If
            Next
    this prints out all the titles of the zip only. do i use this method for treeview1 and scan and match both like this.
    Last edited by doberman2002; Oct 16th, 2019 at 02:14 PM.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Aug 2019
    Posts
    142

    Re: Compare 2 treeviews child items

    Code:
    Dim I As Long, x As Long
    Dim NodX As Node, NodX2 As Node
        Dim lNod As Node, lNod1 As Node
        Dim y As Long
    Dim FoundIt As Boolean
    
    
    For Each NodX In TreeView1.Nodes
    x = NodX.Index
         For Each NodX2 In TreeView2.Nodes
         y = NodX2.Index
    If InStr(TreeView1.Nodes(x).Text, ".zip") And InStr(TreeView2.Nodes(y).Text, ".zip") Then
    If TreeView1.Nodes(x).Text = TreeView2.Nodes(y).Text Then
                   FoundIt = True
                   Exit For
                   End If
             End If
          Next
          If FoundIt Then
     List1.AddItem TreeView2.Nodes(y).Text
          Else
    
          End If
          FoundIt = False
    Next
    in red area i get index out of bounds ?

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width