<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel>
        <title>How to make a treeview with parents</title>
        <description> Hi all,

I thought I share this knowledge I gained about tree and parents.

I have 1 file named contacts. With a ID int and IDParent int field.

The IDParent contains the ID of the Parent in the same file.

To let an entry be a parent of a parent of a parent etc.. I found it was very easy after reading the help instead of coding with trial and error. This way also runs the query ones so, the filling of the treeview is very fast. (I only tested it with a few hundred entries, so if anyone wants to try with more entries and let me (us) know how fast/slow this becomes it would be much appreciated. I hope it is very helpful and if it can be fine-tuned I love to hear it.

So let us start.

I created a query of the datafile called QRY_TreeContacts.


SELECT 
	Contacts.ID AS ID,	
	Contacts.IDParent AS IDParent,	
	Contacts.Name AS Name,	
	Contacts.IsDeleted AS IsDeleted,	
	Contacts.IDIcon AS IDIcon
FROM 
	Contacts
ORDER BY 
	IDParent ASC



My Query 
sRoot is string
sTrash is string
sInbox is string

sParentNode is string

sRoot 	= &amp;quot;Categories&amp;quot;
sTrash 	= &amp;quot;Deleted Items&amp;quot;

sParentNode = &amp;quot;&amp;quot;

TreeDeleteAll(TREE_CONTACTS)
HReadSeek(Icons,ID,1,hIdentical)
TreeAdd(TREE_CONTACTS,sRoot,Icons.Icon,Icons.Icon,0)
HReadSeek(Icons,ID,-11,hIdentical)
TreeAdd(TREE_CONTACTS,sTrash,Icons.Icon,Icons.Icon,-11)

HExecuteQuery(QRY_TreeContacts)
HReadFirst(QRY_TreeContacts)

WHILE NOT HOut()
	
	HReadSeek(Icons,ID,QRY_TreeContacts.IDIcon,hIdentical)
	sParentNode = QRY_TreeContacts.Name
	
	IF NOT QRY_TreeContacts.IDParent = 0 THEN
		sParentNode = TreeFind(TREE_CONTACTS, QRY_TreeContacts.IDParent)
		TreeAdd(TREE_CONTACTS,sParentNode+TAB+QRY_TreeContacts.Name,Icons.Icon,Icons.Icon,QRY_TreeContacts.ID,tvAlphaSort+tvAcceptDuplicate)
	ELSE
		IF NOT QRY_TreeContacts.IsDeleted THEN
			TreeAdd(TREE_CONTACTS,sRoot+TAB+QRY_TreeContacts.Name,Icons.Icon,Icons.Icon,QRY_TreeContacts.ID,tvAlphaSort+tvAcceptDuplicate)
		ELSE IF QRY_TreeContacts.IsDeleted THEN
			TreeAdd(TREE_CONTACTS,sTrash+TAB+QRY_TreeContacts.Name,Icons.Icon,Icons.Icon,QRY_TreeContacts.ID,tvAlphaSort+tvAcceptDuplicate)	
		END
	END
	HReadNext(QRY_TreeContacts)
END

TreeSort(TREE_CONTACTS,sRoot,tvUp)
</description>
        <link>https://www.wxforum.info/read.php?27161,44188,44188#msg-44188</link>
        <lastBuildDate>Tue, 14 Apr 2026 15:21:43 +0200</lastBuildDate>
        <generator>Phorum 5.2.23</generator>
        <item>
            <guid>https://www.wxforum.info/read.php?27161,44188,797767#msg-797767</guid>
            <title>Re: How to make a treeview with parents</title>
            <link>https://www.wxforum.info/read.php?27161,44188,797767#msg-797767</link>
            <description><![CDATA[ can you please explain it more clear did not understood.. :(]]></description>
            <dc:creator>crowntb</dc:creator>
            <category>WinDev Solutions</category>
            <pubDate>Thu, 08 Feb 2024 10:12:30 +0100</pubDate>
        </item>
        <item>
            <guid>https://www.wxforum.info/read.php?27161,44188,145560#msg-145560</guid>
            <title>Re: How to make a treeview with parents</title>
            <link>https://www.wxforum.info/read.php?27161,44188,145560#msg-145560</link>
            <description><![CDATA[ Alexander,<br />
<br />
You are welcome. I am happy I can help as I am helped by others.]]></description>
            <dc:creator>Carlo Hermus</dc:creator>
            <category>WinDev Solutions</category>
            <pubDate>Thu, 31 Jan 2013 16:28:01 +0100</pubDate>
        </item>
        <item>
            <guid>https://www.wxforum.info/read.php?27161,44188,145296#msg-145296</guid>
            <title>Re: How to make a treeview with parents</title>
            <link>https://www.wxforum.info/read.php?27161,44188,145296#msg-145296</link>
            <description><![CDATA[ thank you for your post very much!!! I spent a lot of time to search a solution.]]></description>
            <dc:creator>Alexander S.</dc:creator>
            <category>WinDev Solutions</category>
            <pubDate>Sun, 27 Jan 2013 21:00:49 +0100</pubDate>
        </item>
        <item>
            <guid>https://www.wxforum.info/read.php?27161,44188,44188#msg-44188</guid>
            <title>How to make a treeview with parents</title>
            <link>https://www.wxforum.info/read.php?27161,44188,44188#msg-44188</link>
            <description><![CDATA[ Hi all,<br />
<br />
I thought I share this knowledge I gained about tree and parents.<br />
<br />
I have 1 file named contacts. With a ID int and IDParent int field.<br />
<br />
The IDParent contains the ID of the Parent in the same file.<br />
<br />
To let an entry be a parent of a parent of a parent etc.. I found it was very easy after reading the help instead of coding with trial and error. This way also runs the query ones so, the filling of the treeview is very fast. (I only tested it with a few hundred entries, so if anyone wants to try with more entries and let me (us) know how fast/slow this becomes it would be much appreciated. I hope it is very helpful and if it can be fine-tuned I love to hear it.<br />
<br />
So let us start.<br />
<br />
I created a query of the datafile called QRY_TreeContacts.<br />
<br />
<pre class="bbcode">
SELECT 
	Contacts.ID AS ID,	
	Contacts.IDParent AS IDParent,	
	Contacts.Name AS Name,	
	Contacts.IsDeleted AS IsDeleted,	
	Contacts.IDIcon AS IDIcon
FROM 
	Contacts
ORDER BY 
	IDParent ASC</pre>
<br />
<br />
<pre class="bbcode">
My Query 
sRoot is string
sTrash is string
sInbox is string

sParentNode is string

sRoot 	= &quot;Categories&quot;
sTrash 	= &quot;Deleted Items&quot;

sParentNode = &quot;&quot;

TreeDeleteAll(TREE_CONTACTS)
HReadSeek(Icons,ID,1,hIdentical)
TreeAdd(TREE_CONTACTS,sRoot,Icons.Icon,Icons.Icon,0)
HReadSeek(Icons,ID,-11,hIdentical)
TreeAdd(TREE_CONTACTS,sTrash,Icons.Icon,Icons.Icon,-11)

HExecuteQuery(QRY_TreeContacts)
HReadFirst(QRY_TreeContacts)

WHILE NOT HOut()
	
	HReadSeek(Icons,ID,QRY_TreeContacts.IDIcon,hIdentical)
	sParentNode = QRY_TreeContacts.Name
	
	IF NOT QRY_TreeContacts.IDParent = 0 THEN
		sParentNode = TreeFind(TREE_CONTACTS, QRY_TreeContacts.IDParent)
		TreeAdd(TREE_CONTACTS,sParentNode+TAB+QRY_TreeContacts.Name,Icons.Icon,Icons.Icon,QRY_TreeContacts.ID,tvAlphaSort+tvAcceptDuplicate)
	ELSE
		IF NOT QRY_TreeContacts.IsDeleted THEN
			TreeAdd(TREE_CONTACTS,sRoot+TAB+QRY_TreeContacts.Name,Icons.Icon,Icons.Icon,QRY_TreeContacts.ID,tvAlphaSort+tvAcceptDuplicate)
		ELSE IF QRY_TreeContacts.IsDeleted THEN
			TreeAdd(TREE_CONTACTS,sTrash+TAB+QRY_TreeContacts.Name,Icons.Icon,Icons.Icon,QRY_TreeContacts.ID,tvAlphaSort+tvAcceptDuplicate)	
		END
	END
	HReadNext(QRY_TreeContacts)
END

TreeSort(TREE_CONTACTS,sRoot,tvUp)</pre>
]]></description>
            <dc:creator>Carlo Hermus</dc:creator>
            <category>WinDev Solutions</category>
            <pubDate>Thu, 07 Jan 2010 00:55:18 +0100</pubDate>
        </item>
    </channel>
</rss>
