Solved

TreeView Sorting

Posted on 2007-03-31
12
1,608 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]
Comment Utility
can you draw how the treeview is / should be organized?
also, how do you fill it?
0
 

Author Comment

by:ibrobar
Comment Utility
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]
Comment Utility
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
 

Author Comment

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

Author Comment

by:ibrobar
Comment Utility
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
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:ibrobar
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The viewer will learn how to implement Singleton Design Pattern in Java.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now