title: Creating parent and child nodes with a treeview and duplicate strings
body: <p>I am creating a GUI based script that when the user enters a username, it retrieves a comma delimited log file with information like date and time logged in, the machine they logged into, etc.
  As part of the GUI I would like to use a TreeView to present them with a list of the MAC addresses that the username they entered has logged into.
  In some cases there are many duplicates, for different times logged in over the course of a year.
  I would like to be able to display the unique instances as parent nodes, and then for each duplicate instance, add it as a child node to the corresponding parent node along with the time they logged in.</p>
  
  <p>I have what i think is part of the solution, the adding of the unique nodes, and its working as i expected, but am having quite a tough time adding the duplicate nodes as child nodes to the corresponding parent nodes.</p>
  
  <p>Ex: if the user has logged into hostname COMP1, 6 times throughout the log file, I want to display COMP1 as a parent node and if the users presses the + symbol, they will see the 6 instances listed below with the date property attached.</p>
  
  <p>Here is a sample from the .CSV log file, properties at the top line:</p>
  
  <pre><code>Date,EventType,ConnectionType,UserDomain,UserLogonTime,LogonType,HostName,HostAddress,HostStartTime,RemoteStationName,RemoteStationAddress
  3/24/2015 12:49:58 PM,Logon,Local,DOMAIN,3/24/2015 12:49:13 PM,CONSOLE,F0A8F0B01660,10.10.10.11,3/24/2015 12:27:15 PM,N/A,N/A
  3/26/2015 12:32:56 PM,TS Session Connected,Remote-RDP,DOMAIN,3/24/2015 7:13:19 AM,CONSOLE,VFP3077V,10.10.10.10,3/23/2015 6:56:32 AM,Dingus,10.10.96.72
  </code></pre>
  
  <p>The properties I'm selecting from the log file are hostname and date.</p>
  
  <p>Here is some of my current code:</p>
  
  <pre><code>$array = Import-Csv $filepath\$username.txt | Where-Object {$_.EventType -eq  "TS   Session Connected" -or $_.EventType -eq "Logon"} | select -ExpandProperty     hostname | sort -Unique
  
  $array2 = Import-Csv $filepath\$username.txt | Where-Object {$_.EventType -eq "TS Session Connected" -or $_.EventType -eq "Logon"} | select -ExpandProperty Date | sort -Unique
  
  #Loops through and singles out each host name, and adds it as a treenode 
  for ($i = 0; $i -lt $array.Count; $i++) {
  $node = $treeviewHostnames.Nodes.Add($array[$i]) | Out-Null
  }
  </code></pre>
  
  <p>The treeview object:</p>
  
  <pre><code>$treeviewHostnames = New-Object System.Windows.Forms.TreeView
  $treeviewHostnames.size = New-Object drawing.Size @(300,378)
  $treeviewHostnames.Location = New-Object drawing.Size @(380,165)
  $treeviewHostnames.Scrollable = $true
  </code></pre>
  
  <p>This adds a unique list of hostnames to my treeview object but I'm having a tough time adding the specific duplicate child hostnames to the unique parent hostnames.</p>