Solved

TreeView Sorting

Posted on 2007-03-31
12
1,615 Views
Last Modified: 2013-11-23
Hi

I have a TreeView of Years and Months and I want to sort it probebly. I am using the alphasot method and it's working for the years but it's mixing up the months order , so how can i solve this problem.
please help.

thanks
0
Comment
Question by:ibrobar
  • 7
  • 3
  • 2
12 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18828263
can you draw how the treeview is / should be organized?
also, how do you fill it?
0
 

Author Comment

by:ibrobar
ID: 18828271
Hi Angelll

I am filling the treeview from a table.
my tree is as follow :
Library
     2000
         Jan
         Feb
         Mar
    2001
         Jan
         Feb

and so on
so if I add new year like 1974 should goes first and if i add new month should  be the last node

thanks
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18828292
i fear that with D programming, that is not possible, except removing and readding all other child nodes at that level in the correct order...
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:ibrobar
ID: 18828312
I think if we use the CustomSort procedure it will help but i am not sure how
0
 

Author Comment

by:ibrobar
ID: 18841579
Hi

so no solution upto now , please somebody help.
Is it possible that i cann't do two sorting on one tree , one sort for level one nodes and the other is for level two nodes

regards
0
 
LVL 1

Expert Comment

by:swiatlo
ID: 18849525
Sort items using TStringList.
Add string formated as 'yyyymm' ( '200100','200101'..'200112') and objects (pointers to nodes or structured information).
Use
TStringList.AddObject(const S: string; AObject: TObject )
set TStringList.Sort:=true

0
 

Author Comment

by:ibrobar
ID: 18855519
Hi Swiatlo

THanks for your help but could you please write me the code cause I never dealt with TstringList and I will increase the points if you gave me an accpeted solution
0
 
LVL 1

Expert Comment

by:swiatlo
ID: 18856824
I just came to a second solution.
Why not add nodes in format 'YYYYMM', Run AlphaSort and then replace all
YYYYMM to proper strings that
'200100' will become a year '2001',
'200105' will become a month 'May'
0
 

Author Comment

by:ibrobar
ID: 18862538
Hi Swiatlo

I read your new solution, but if I applied the alphasort it will sort the month belonging to each year in alphabetic sorting like April will be the first and this my problem in the first place cause i wanna the months to be sorted in it's real order not in alphabetic one

regards
0
 
LVL 1

Accepted Solution

by:
swiatlo earned 50 total points
ID: 18862881
AlphaSort will end up with order

200100  //2001
  200102 //Feb
  200104 //Apr
  200105 //May
200200
200300
  200304
  200311
...
...
and after sort  replace those strings with Aprils, Mays and what ever you like
0
 

Author Comment

by:ibrobar
ID: 18863157
Hi Swiatlo

I will try it today and i will let you know , it a kind of misleading but clever way.

thanks
0
 

Author Comment

by:ibrobar
ID: 18868781
Hi again Swiatlo

Actullay I used part of your solution , you gave me the idea.
I used a field I called it Mask , and i put in it 200100 when my year field is 2001 and so on like below
 Mask     // year
200100  // 2001
200102  // Feb
200104  // Apr
200105  / /May
But I added to this (instead of Replacing those strings with Aprils, Mays) I used secondary index on the field Mask so my tree came sorted in the way i want when i loaded to the treeview using the field year.

any way thanks a lot and best regards.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
while loop over for loop 7 101
has12 challenge 13 68
static class 3 68
Specific format 21 196
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question