Problem when populate treeview control with hierarchical data from Excel Sheet

kuldokk

New Member
Joined
Oct 16, 2014
Messages
26
I am currently using a treeview control from Treeview Control from JKP. Trying to populate the tree with hierarchical data from an Excel Sheet, I encountered this problem: the tree I populated does not reflect the data. In this picture <code style="margin: 0px; padding: 1px 5px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: pre-wrap; background-color: rgb(238, 238, 238);">AP0004</code> should be under <code style="margin: 0px; padding: 1px 5px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: pre-wrap; background-color: rgb(238, 238, 238);">TP0002
</code>
mcknM.png


The code I've tried is this

Code:
[/FONT]<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">[COLOR=#00008B]For[/COLOR][COLOR=#000000] [/COLOR][COLOR=#00008B]Each[/COLOR][COLOR=#000000] c [/COLOR][COLOR=#00008B]In[/COLOR][COLOR=#000000] Sheet14[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Range[/COLOR][COLOR=#000000]([/COLOR][COLOR=#800000]"A2:A"[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]&[/COLOR][COLOR=#000000] Sheet14[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Range[/COLOR][COLOR=#000000]([/COLOR][COLOR=#800000]"A"[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]&[/COLOR][COLOR=#000000] Rows[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Count[/COLOR][COLOR=#000000]).[/COLOR][COLOR=#00008B]End[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000]xlUp[/COLOR][COLOR=#000000]).[/COLOR][COLOR=#000000]Row[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]

    [/COLOR][COLOR=#00008B]On[/COLOR][COLOR=#000000] [/COLOR][COLOR=#00008B]Error[/COLOR][COLOR=#000000] [/COLOR][COLOR=#00008B]Resume[/COLOR][COLOR=#000000] [/COLOR][COLOR=#00008B]Next[/COLOR][COLOR=#000000]
    [/COLOR][COLOR=#808080]'Populate level 1[/COLOR][COLOR=#000000]
    [/COLOR][COLOR=#00008B]Set[/COLOR][COLOR=#000000] cRoot [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]AddRoot[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000]sKey[/COLOR][COLOR=#000000]:=[/COLOR][COLOR=#000000]c[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Value2[/COLOR][COLOR=#000000],[/COLOR][COLOR=#000000] vCaption[/COLOR][COLOR=#000000]:=[/COLOR][COLOR=#000000]c[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Value2[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]

    [/COLOR][COLOR=#00008B]Set[/COLOR][COLOR=#000000] cExtraNode [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] cRoot[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]AddChild[/COLOR][COLOR=#000000]([/COLOR][COLOR=#800000]"ML_"[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]&[/COLOR][COLOR=#000000] c[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Value2[/COLOR][COLOR=#000000],[/COLOR][COLOR=#000000] [/COLOR][COLOR=#800000]"Meilensteine"[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]

    [/COLOR][COLOR=#808080]'Populate level 2[/COLOR][COLOR=#000000]
    [/COLOR][COLOR=#00008B]Set[/COLOR][COLOR=#000000] cNode [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] cRoot[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]AddChild[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000]c[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Offset[/COLOR][COLOR=#000000](,[/COLOR][COLOR=#000000] [/COLOR][COLOR=#800000]1[/COLOR][COLOR=#000000]).[/COLOR][COLOR=#000000]Value2[/COLOR][COLOR=#000000],[/COLOR][COLOR=#000000] c[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Offset[/COLOR][COLOR=#000000](,[/COLOR][COLOR=#000000] [/COLOR][COLOR=#800000]1[/COLOR][COLOR=#000000]).[/COLOR][COLOR=#000000]Value2[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]

    [/COLOR][COLOR=#808080]'Populate level 3[/COLOR][COLOR=#000000]
    [/COLOR][COLOR=#00008B]If[/COLOR][COLOR=#000000] cNode[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Level [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] [/COLOR][COLOR=#800000]2[/COLOR][COLOR=#000000] [/COLOR][COLOR=#00008B]Then[/COLOR][COLOR=#000000] [/COLOR][COLOR=#00008B]Set[/COLOR][COLOR=#000000] cNode [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] cNode[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]ParentNode

    [/COLOR][COLOR=#00008B]If[/COLOR][COLOR=#000000] [/COLOR][COLOR=#00008B]Not[/COLOR][COLOR=#000000] IsEmpty[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000]c[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Offset[/COLOR][COLOR=#000000](,[/COLOR][COLOR=#000000] [/COLOR][COLOR=#800000]2[/COLOR][COLOR=#000000]).[/COLOR][COLOR=#000000]Value2[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000] [/COLOR][COLOR=#00008B]Then[/COLOR][COLOR=#000000]
        [/COLOR][COLOR=#00008B]Set[/COLOR][COLOR=#000000] cNode [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] cNode[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]AddChild[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000]c[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Offset[/COLOR][COLOR=#000000](,[/COLOR][COLOR=#000000] [/COLOR][COLOR=#800000]2[/COLOR][COLOR=#000000]).[/COLOR][COLOR=#000000]Value2[/COLOR][COLOR=#000000],[/COLOR][COLOR=#000000] c[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Offset[/COLOR][COLOR=#000000](,[/COLOR][COLOR=#000000] [/COLOR][COLOR=#800000]2[/COLOR][COLOR=#000000]).[/COLOR][COLOR=#000000]Value2[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]
    [/COLOR][COLOR=#00008B]End[/COLOR][COLOR=#000000] [/COLOR][COLOR=#00008B]If[/COLOR][COLOR=#000000]

    [/COLOR][COLOR=#808080]'Populate level 4[/COLOR][COLOR=#000000]
    [/COLOR][COLOR=#00008B]If[/COLOR][COLOR=#000000] [/COLOR][COLOR=#00008B]Not[/COLOR][COLOR=#000000] IsEmpty[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000]c[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Offset[/COLOR][COLOR=#000000](,[/COLOR][COLOR=#000000] [/COLOR][COLOR=#800000]3[/COLOR][COLOR=#000000]).[/COLOR][COLOR=#000000]Value2[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000] [/COLOR][COLOR=#00008B]Then[/COLOR][COLOR=#000000]
        [/COLOR][COLOR=#00008B]If[/COLOR][COLOR=#000000] cNode[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Level [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] [/COLOR][COLOR=#800000]2[/COLOR][COLOR=#000000] [/COLOR][COLOR=#00008B]Then[/COLOR][COLOR=#000000]
            [/COLOR][COLOR=#00008B]Set[/COLOR][COLOR=#000000] cNode [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] cNode[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]AddChild[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000]c[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Offset[/COLOR][COLOR=#000000](,[/COLOR][COLOR=#000000] [/COLOR][COLOR=#800000]3[/COLOR][COLOR=#000000]).[/COLOR][COLOR=#000000]Value2[/COLOR][COLOR=#000000],[/COLOR][COLOR=#000000] c[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Offset[/COLOR][COLOR=#000000](,[/COLOR][COLOR=#000000] [/COLOR][COLOR=#800000]3[/COLOR][COLOR=#000000]).[/COLOR][COLOR=#000000]Value2[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]
            [/COLOR][COLOR=#00008B]Set[/COLOR][COLOR=#000000] cNode [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] cNode[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]ParentNode
        [/COLOR][COLOR=#00008B]ElseIf[/COLOR][COLOR=#000000] cNode[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Level [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] [/COLOR][COLOR=#800000]1[/COLOR][COLOR=#000000] [/COLOR][COLOR=#00008B]Then[/COLOR][COLOR=#000000]
            [/COLOR][COLOR=#00008B]Set[/COLOR][COLOR=#000000] cNode [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] cNode[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Child[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]AddChild[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000]c[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Offset[/COLOR][COLOR=#000000](,[/COLOR][COLOR=#000000] [/COLOR][COLOR=#800000]2[/COLOR][COLOR=#000000]).[/COLOR][COLOR=#000000]Value2[/COLOR][COLOR=#000000],[/COLOR][COLOR=#000000] c[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Offset[/COLOR][COLOR=#000000](,[/COLOR][COLOR=#000000] [/COLOR][COLOR=#800000]2[/COLOR][COLOR=#000000]).[/COLOR][COLOR=#000000]Value2[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]
            [/COLOR][COLOR=#00008B]Set[/COLOR][COLOR=#000000] cNode [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] cNode[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Child[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]AddChild[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000]c[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Offset[/COLOR][COLOR=#000000](,[/COLOR][COLOR=#000000] [/COLOR][COLOR=#800000]3[/COLOR][COLOR=#000000]).[/COLOR][COLOR=#000000]Value2[/COLOR][COLOR=#000000],[/COLOR][COLOR=#000000] c[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Offset[/COLOR][COLOR=#000000](,[/COLOR][COLOR=#000000] [/COLOR][COLOR=#800000]3[/COLOR][COLOR=#000000]).[/COLOR][COLOR=#000000]Value2[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]
            [/COLOR][COLOR=#00008B]Set[/COLOR][COLOR=#000000] cNode [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] cNode[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]ParentNode
        [/COLOR][COLOR=#00008B]End[/COLOR][COLOR=#000000] [/COLOR][COLOR=#00008B]If[/COLOR][COLOR=#000000]
    [/COLOR][COLOR=#00008B]End[/COLOR][COLOR=#000000] [/COLOR][COLOR=#00008B]If[/COLOR][COLOR=#000000]
[/COLOR][COLOR=#00008B]Next[/COLOR]</code>[FONT=Arial]

There must be something wrong with my approach here. Any suggestion? Thanks a lot.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Forum statistics

Threads
1,215,063
Messages
6,122,935
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top