Topic: Sort Treeview

Hello to all !

In the PJ project, I added two buttons (Up and Down) under the Treeview of Form1 to rearrange the parents and children added as I went.
I used two scripts offered on the MVD forum (by Dmitri). In my case, neither of the two work.
But still an error message (Limit out of index) and the MVD debugger always puts it in the same place (apparently without cause and effect).
For the past few days, I've been going around in circles to try to solve this eye-popping anomaly.
In desperation, I appeal to new eyes.
Thank you in advance to anyone who can solve this annoying problem.
JB

Post's attachments

Attachment icon TEST_PAPILLONS.rar 1.85 mb, 249 downloads since 2021-02-15 

Re: Sort Treeview

Hello Jean,


I had a look at your project (because I like it !) and haven't found yet why your reordering function does not work, but I think I found the reason of your "out of index" error.


Line 762 of your script reads :


Form1.TableGrid1.Cell[1,i].TextColor := clRed;     // Les caractères de la colonne sont en rouge

At this place your are in a loop, iterating through your columns. But this line deals with cells and you did not iterate.

I replaced this line with :

for i := 0 to c do
     begin
          Form1.TableGrid1.Cell[1,i].TextColor := clRed;     // Les caractères de la colonne sont en rouge
      end;

And the error message is gone.

Hope this will help a little, I will dive into your other problem smile

Cheers

Mathias

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: Sort Treeview

Hello again,


I am a bit lost. What is it exactly that you want to achieve ? Reorder the sibling into a same family (as long as there is more than one) ? Change the order of the families ? Change a sibling to another family ?


In any case, you refer in your queries to a "record_count" field that I believe to be a counter. But what increments it ? I opened the database and found only null values in this field so there is no comparison possible as per your code :


record_count1 := SQLExecute('SELECT record_count FROM OrgStructure WHERE id='+IntToStr(id1));
record_count2 := SQLExecute('SELECT record_count FROM OrgStructure WHERE id='+IntToStr(id2));

if (record_count1<>'') and (record_count2<>'') then

I usually add an "order" column to my tables and adjust their content according to the user choice for the order of display. Is it what you intended to achieve ?


I any case keep me posted, I love your application it's great !!

Cheers


Mathias

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: Sort Treeview

Hello Mathias,

Glad to see you back on the MVD forum:

About the loop:
It's a mistake on my part, I forgot to define my loop (for i ...)
Especially since I have previously declared my variable (i)

About the reorganization:
2 cases considered:
- Alphabetically reorganize the sub-families (child) as well as the families (parent)
As I pick up new butterflies, I may need to pick up a new family and sometimes a new subfamily. The new families and sub-families are added at the end of the Treeview without being inserted alphabetically between them.
The alphabetical reorganization of the Treeview must be done on both fields.
What is a shame is that I checked the RowMoving and KeepUserSort properties and apparently this has no action.
I appreciate your interest in this annoying problem.

Cheers
JB