Results 1 to 3 of 3

Thread: Re: Treeview - Check all Child Nodes on checking parent node

  1. #1

    Thread Starter
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    696

    Re: Treeview - Check all Child Nodes on checking parent node

    One thing i'm still wondering is how you would combine the child nodes of nodes that have the same text or key.

    for example I have a node with say: "[E886B7DEA0BE6AA0CB34F623924A3AD2]"

    And another node has that same value, How would I place the child nodes of those 2 separate nodes (that have the same text value) into 1 node so that I don't have duplicate nodes with the same value (for an md5 hash)?

    Preview:


    The ones surrounded by the red box have the same value for the node. How would I combine all of the child nodes of those duplicates, into one node?

    So that it would be
    • 1A6078D4ED851036DD2A91CBB26A729E
      • item from this node
      • Item from other node with the same MD5 hash value
      • Item from other node with the same MD5 hash value
      • Item from other node with the same MD5 hash value


    ect...

    I realise that it would be faster done, if it was sorting them out this way while they are added to the control, but either way should work fine for me. Whether they are sorted after they get added, or as they get added. The files are going to be mixed up anyway as they get added, the "scan" doesn't look for a specific md5 in the file, it calculates the md5 as it goes into the control, so adding them in the correct nodes as the nodes get added to the control would be random sorting anyway. It would have to compare the md5 to the value of the node to determine if the md5 exists, or if it doesn't exist, to determine whether it goes in along with another child node in a parent node or not.
    Last edited by AceInfinity; Jul 7th, 2011 at 03:54 AM.
    <<<------------
    Improving Managed Code Performance | .NET Application Performance
    < Please if this helped you out. Any kind of thanks is gladly appreciated >


    .NET Programming (2012 - 2018)
    ®Crestron - DMC-T Certified Programmer | Software Developer
    <<<------------

  2. #2
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Treeview - Check all Child Nodes on checking parent node

    If you follow a pattern similar to what I've done below, you will get the desired result. And yes, you should be doing this before you add the nodes. Not adding the nodes and then rearranging them.
    Code:
    Public Class Form1
    
        '//fields
        Private md5Dictionary As New Dictionary(Of String, TreeNode)()
    
        '//event handlers
        Private Sub Button1_Click(ByVal sender As System.Object, _
                                  ByVal e As System.EventArgs) Handles Button1.Click
    
            '//lets say these are some of the hashes (two duplicates)
            Dim hashes = New String() {"[E886B7DEA0BE6AA0CB34F623924A3AD2]", _
                                       "[AS823N239XM29323RKJ2H3K23KD2K3SS]", _
                                       "[KJH23KH2K3T239829829230H23KK3H2K]", _
                                       "[E886B7DEA0BE6AA0CB34F623924A3AD2]"}
    
            '//lets say that these 4 files correspond to the above 4 hashes
            Dim files = New String() {"C:\test\file.txt", _
                                      "C:\Program Files\system.dll", _
                                      "C:\test\source.xml", _
                                      "C:\test\file - Copy.txt"}
    
    
            Dim fileIndex = 0
            For Each hash In hashes
    
                '//check in your dictionary if the hash has already been added
                If Me.md5Dictionary.ContainsKey(hash) Then
    
                    '//we've already seen this hash
                    Me.md5Dictionary(hash).Nodes.Add(files(fileIndex))
                Else
    
                    '//haven't encountered this hash yet
                    Dim node = Me.TreeView1.Nodes.Add(hash)
    
                    '//add the actual file value to the hash node
                    node.Nodes.Add(files(fileIndex))
    
                    '//add a new dictionary entry
                    Me.md5Dictionary.Add(hash, node)
                End If
                fileIndex += 1
            Next
    
            Me.TreeView1.ExpandAll()
        End Sub
    
    End Class
    Output:
    Name:  TreeView.png
Views: 2916
Size:  24.7 KB

  3. #3

    Thread Starter
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    696

    Re: Treeview - Check all Child Nodes on checking parent node

    That's going to take a little bit of modification to make this work, but I understand the code. I'm going to have to design a loop to look through the nodes as they get added instead of using defined string arrays like above...
    <<<------------
    Improving Managed Code Performance | .NET Application Performance
    < Please if this helped you out. Any kind of thanks is gladly appreciated >


    .NET Programming (2012 - 2018)
    ®Crestron - DMC-T Certified Programmer | Software Developer
    <<<------------

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