Hello:
Many may have seen the struggle I am having with sorting a TREEVIEW. After many, many hours I am trying to think of another way of accomplishing this.
I thought perhaps I could write the TV to an ASCII file, then sort that file and then relabel it, followed by a re-reading into a TV.
So, if I can get any help it would be greatly appreciated.
I am able to export the file to an ASCII TAB Delimited file as follows:
So now what I need to do is sort anything that ends with an "*" to the bottom of its section/node.
I have to keep the integrity of the the nodes and tab delimited file, so I can read it back in.
Start at the highest level.. And sort everything ending with an "*" at that level to the bottom. (Within that node)
So (Level2) AB and AC will go to the end. AND everything under it.
Next go to the next level (Level3) ACA will go to the end of it's level.
Next go to the next level (level4). AAB1 will go after AAB4 and ABB3 will go after ABB4.
If someone can help me with this, it would be greatly appreciated.
The next step would be to then go back through the newly sorted file and rename the left side of the values. AA, AAA, AAA1, etc. back to the original order. So, if you can provide that piece of code as well, it would be greatly appreciated. But I think I can figure that part out, if I can just get some help with the sorting of the file.
Hello:
I have worked through an example, hoping this makes what is needed a little clearer.
Thank you in advance for any and all support.
Thanks.
I need a small piece of code that will read an ASCII Delimited file and sort it, with the following rules.
This might seem complicated, but I think a good tight loop or two should accomplished what is needed.
NOTE: the tabs and delimiters need to remain so it can be re-read into a TREEVIEW.
INPUT: Tab delimited ASCII File.
OUTPUT: Tab delimited ASCII File with values ending with an "*" are sorted to the end of their node.
-This file should be thought of as a TREE Structure
-The left side of the labels. DO NOT MOVE
-The right side of the labels DO MOVE
-The left and right are determined by the first space on the right side
So using this as an example: AA 8975043*
AA+SPACE(8) is the left label
8975043* is the right label
AA+SPACE(8) will not move
8975043* - since it ends with an "*" will be moved to the end of the NODE
1. All right labels ending with an "*" need to be moved/sorted to the end of their node
2. Start with the second level and sort the items ending with an "*" to the end of that node
So:
AA 8975043*
AB 175063*
AC 75083
AD 75003
Becomes:
AA 75083
AB 75003
AC 8975043*
AD 175063*
NOTE: the AA, AB, AC, AD labels DO NOT MOVE
3. The values under each node ARE MOVED AS WELL.
So:
First - You want to retain Tabs in your ASCII data - Substitute a special Character for each as you extract your data to be sorted
eg, AA123456 <TAB> 1234 Could be extracted as AA123456:1234
You want to actually change the prefix of the data if it has an * - then change it as you create the data to be sorted (NOT WHILE YOU ARE SORTING)
To sort data of the quantity you have you have 2 alternatives
1) Update a Table in Access Database then using SQL use a Select statement ASC (Ascending) to sort it (Select * from myTable Order By MyData ASC)
2) Use a List Component on a Form which has been set up to be Sorted and add your data to it (Make it Not Visible). Then read the data back 1 row at a time and it will come back sorted
Option 2 is the easiest as you don't need a database
I would think this all could be easily accomplished with an internal data structure that you create, without creating any external files or databases. Then again, I am a C++ programmer. When I used to program in VB, I would create a user defined type to represent the nodes in a tree data structure. Then I would create an array of these nodes and use the array indexes as pointers. (I love pointers. )
Maybe you could put the data into a two dimensional array with a column for each level. Then sort the table as if the all of the columns are one big column. Then relabel the left side of the labels so that they are in order. When you extract the data from the sorted table, check if the left side of each label is different than the previous row. This will indicate that the previous row was a leaf in the tree.
Bookmarks