By "compressed CSV file" I mean one in which missing leading fields in one line are assumed to match the corresponding fields in the previous line. For example, this CSV file:
Food
Food,Vegetables
Food,Vegetables,Beans
Food,Vegetables,Peas
is equivalent to this compressed CSV file:
Food
,Vegetables
,,Beans
,,Peas
For a large file containing a deeply nested hierarchy, the compressed version may be much smaller.
Read the whole file into a string. Use Split to split the file into lines.
For each line, use Split to break the line into fields. Compare the fields in the line to those in the previous line to see where the lines first differ. If a field in the new line is empty, assume the two values match. Create new TreeView nodes for the fields after this point of first difference.
Store the most recently created node at each level of indentation in the tree_nodes array so you can use it as the parent of the next node below that level.
|