Hello,

I am severely confused while trying to do some thing like this with treeview. Need help please... I am trying to populate an treeview by reading lines from an text file.

The text file contains the paths of the in the format below

[TOPROOT]
[TOPROOT\NULL]
[TOPROOT\NULL]
[TOPROOT\NULL\COMMONDT]
[TOPROOT\EVENT]
[TOPROOT\EVENT\ROTO]
[TOPROOT\EVENT\ROTO\CLSID0001]
[TOPROOT\EVENT\ROTO\CLSID0001\CLSID_ID]


I am trying to make the treeview using the paths as above with the top node as TOPROOT and the child node as NULL. When the program I have written reads the third line which is repeated again the program quits with an error "key not unique". Unfortunately I cannot prevent the lines in the text file from duplicating as this output is generated by another program.

It would be great if any one can give me some logic as to create the tree structure reading the paths mentioned in the text file.

Thanks in advance...

The code i am trying till now...


The Code Till Now Code:
  1. Dim Filenum As Integer
  2. Dim Temp As String
  3. Dim Arr() As String
  4. Dim x As Long
  5. Dim k As Integer
  6. Dim nodx As Node
  7.  
  8. Filenum = FreeFile
  9. Open App.Path & "\test.txt" For Input As #Filenum
  10. Do Until EOF(Filenum) = True
  11. Line Input #Filenum, Temp
  12.     If Left$(Temp, 1) = "[" Then
  13.         Arr() = Split(Replace(Replace(Temp, "[", vbNullString), "]", vbNullString), "\")
  14.  
  15.         If UBound(Arr) = 0 Then
  16.             Set nodx = Tv1.Nodes.Add(, , Arr(0), Arr(0))
  17.             nodx.Expanded = True
  18.         Else
  19.             For k = 0 To UBound(Arr)
  20.                 If k > 0 Then
  21.                     Set nodx = Tv1.Nodes.Add(Arr(k - 1), tvwChild, Arr(k), Arr(k))
  22.                 'Else
  23.                  '   Set nodx = Tv1.Nodes.Add(Arr(0), tvwChild, Arr(k), Arr(k))
  24.                 End If
  25.             Next
  26.         End If
  27.         x = x + 1
  28.     End If
  29. Loop
  30. Close #Filenum



-Putta