Solved

TreeView Sorting

Posted on 2007-03-31
12
1,618 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
  • 2
12 Comments
 
LVL 143

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 143

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
countTriple  challenge 8 85
map interface methods 3 78
scoresSpecial  challenge 13 63
Work with App store 7 90
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
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 goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

735 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