1 (edited by salvatorevicari85 2024-06-29 21:46:04)

Topic: TreeView Basic Operation

I've been trying to work with TreeView for a while.
I can't get it to work.

I also tried to download other examples from the Forum but I don't understand what the trick is.
I attach the basis of my project.

Help please.
Thank's

Post's attachments

Attachment icon TreeView - Base.rar 315.75 kb, 43 downloads since 2024-06-29 

Re: TreeView Basic Operation

Hi,
There are a couple of things you need to understand with 'treeview' and its underlying data structure.
1.  at its simplest, you only need to have one table (for example 'my_structure').  In 'my_structure' you only need to typically have 2 fields - the name of the 'node' in the 'treeview' and a description of the node (the description isn't necessary but can be useful).
2.  when designing your 'treeview', there are two things to be aware of;
2.1  you need to make the 'treeview' editable (see the attached screenshot).
2.1  optionally, you need to specify a form where you enter information about each node (see the attached screenshot).  If you do not use a separate form (form2 in the attached example), you get the default option which only allows you to enter the node name and nothing else (which is okay if your requirement is very simple but limits you if you need to add additional information about the node).
3.  any additional related tables are not relevant to the structure itself but are simple look-up tables with values that add extra information to the node (in the attached example, the values of 'maschio' and 'femmina' (held in the 'seeso' table) would not be a new node in the structure, they are just information relating to a particular node in the structure.
It sounds far more complicated trying to descibe it than it actually is smile.  Have a look at the attachment and shout out if something is unclear.
Regards,
Derek.

Post's attachments

Attachment icon TreeView - Base1.zip 495.2 kb, 32 downloads since 2024-06-30 

Re: TreeView Basic Operation

Hello Salavatore, Hello Derek (How are you ?)
To illustrate what Derek rightly says about using a TreeView in MVD, here is an example of what you get with a TV.
I admit that the one used by MVD is not great in my opinion, I would have preferred a TV like in Delphi7 much simpler to implement.
To illustrate what Derek describes, in my application on the management of a database on birds responding to a command, the choice of a family in the initial TV displays the different birds belonging to this family and a click on the name of a bird calls the form describing it (with photo and song, or even video when it exists).
At first, I had trouble understanding the philosophy of MVD's TV.
After many emails with Dmitri, I managed to master it, but it took time.
Hang in there if you want to get there, don't forget to allow users to create parents and children, you can also automatically sort alphabetically without using Up and Down buttons (like I did at the beginning - it's a pain!)
Good luck and if you need anything, come back to us, you will have all the necessary information.
JB

Post's attachments

Attachment icon Exemple.jpg 432.69 kb, 17 downloads since 2024-06-30 

Re: TreeView Basic Operation

Thanks Derek, thanks jean.brezhonek

Ok, we're almost there.
Making the TV editable was important and I managed to get a first result.
But with the logic I still have a doubt.
I noticed that the TV allows you to always save to the same "Parent" table.
But then what is the "Children's Table" really for?
I saw that it is necessary to insert the foreign key when configuring the TV tool in MVD (therefore opening "settings"), but then in fact the connection with the "Children Table" is of no use.
If I look at Derek's example, by opening the "Settings" I notice that the foreign key remained set on the "People" table which however was deleted.
I am attaching:
- my first working project,
- screenshot of foreign key to Derek's file. (Inside my first working project).

Post's attachments

Attachment icon TreeView - Base 2.rar 333.5 kb, 50 downloads since 2024-06-30 

Re: TreeView Basic Operation

Hi Salvatore, Salut Jean (oui, tout va bien ici, merci.  Et chez toi ?),
In my previous example, the foreign key setting was left over from your original attachment - it didn't need to be there.  Instead, it should be set as per 'screenshot1' in the attachment.
To clarify, there are three things that you need to set correctly.
1.  In the data schema, the table that contains your treeview structure must have a field called 'parentid' (defined as integer).   
2.  The 'foreign key' in the 'treeview' settings screen can simply be the name of the table that holds the structure of your treeview (the 'foreign key' label is perhaps a bit misleading).  You can simply type in the name of the table manually. 
3.  Select 'parentid' in the 'parent id field (see 'screenshot1').
There is no requirement for a separate 'childrens table' - that is the whole point of using a 'treeview';  all of the 'child' records are held in the same table as their 'parent' and they are linked back to their relevant parent by the 'parentid' field. 
Have a look at 'screenshot2' in the attachment which hopefully clarifies this;  this is a view of the raw data (using SQLiteStudio) which shows, for example, that the entry 'Hollywood' has an ID of 19.  All of the records that are 'children' of 'Hollywood' have their own IDs BUT HAVE A PARENTID OF 19 - this is how the relationship is automatically maintained.
IF YOU WERE USING TABLEGRIDS, then you would have TWO TABLES (eg 'groups' and 'members' with a foreign key maintaining the relationship between them).  But with 'treeviews' all of the informaiton is held in A SINGLE TABLE with the relationship being maintained instead by a 'parentid';  this is the fundamental difference.
Derek.

Post's attachments

Attachment icon TreeView - Base1a.zip 556.53 kb, 49 downloads since 2024-07-01 

Re: TreeView Basic Operation

Now it's clear.
Unfortunately, the logic is not explained clearly in the MVD guide, and the procedure for creating a basic model is also missing.
Thanks so much for the help guys.