Jump to content

need help to create a treeview linked with array


Recommended Posts

good morning
this is the first post here in the autoit forums
i hope that you can help me in my problem
i have a JSON encoded
it a map of my forums
where i want to make a treeview that have the same type of map
e.g
a system (as category)
windows (as sub category)
software (as an child item in the windows category)
.....
i don't know how to do that
so, i know that i can do that using the json functions
but i need your help about how we can do it as the type that i told you
by the way i need to put the sub info for each item in an array that give me the ability to manage my items
e.g
can post thread
can reply
message cound ...
you just give me a small example and i can continue.
am sorry if this against the rules of the forum.
but i realy searched a lot but i couldn't
i hope some one give me the way.
thank you very much in advance

 

here is the link of json forum
https://www.autoitscript.com/forum/topic/148114-a-non-strict-json-udf-jsmn/

and here is my encoded json file

 

{
    "tree_map": {
        "0": [
            1,
            5,
            6,
            7
        ],
        "1": [
            2
        ],
        "2": [
            4
        ],
        "5": [
            3
        ],
        "6": [
            8
        ],
        "8": [
            9,
            10
        ]
    },
    "nodes": [
        {
            "breadcrumbs": [],
            "description": "",
            "display_in_list": true,
            "display_order": 1,
            "node_id": 1,
            "node_name": null,
            "node_type_id": "Category",
            "parent_node_id": 0,
            "title": "Main category",
            "type_data": {}
        },
        {
            "breadcrumbs": [
                {
                    "node_id": 1,
                    "title": "Main category",
                    "node_type_id": "Category"
                }
            ],
            "description": "",
            "display_in_list": true,
            "display_order": 1,
            "node_id": 2,
            "node_name": null,
            "node_type_id": "Forum",
            "parent_node_id": 1,
            "title": "Main forum",
            "type_data": {
                "allow_poll": true,
                "allow_posting": true,
                "can_create_thread": true,
                "can_upload_attachment": true,
                "discussion_count": 0,
                "last_post_date": 0,
                "last_post_id": 0,
                "last_post_username": "",
                "last_thread_id": 0,
                "last_thread_prefix_id": 0,
                "last_thread_title": "",
                "message_count": 0,
                "min_tags": 0,
                "require_prefix": false
            }
        },
        {
            "breadcrumbs": [
                {
                    "node_id": 1,
                    "title": "Main category",
                    "node_type_id": "Category"
                },
                {
                    "node_id": 2,
                    "title": "Main forum",
                    "node_type_id": "Forum"
                }
            ],
            "description": "",
            "display_in_list": true,
            "display_order": 1,
            "node_id": 4,
            "node_name": null,
            "node_type_id": "Forum",
            "parent_node_id": 2,
            "title": "my forums1",
            "type_data": {
                "allow_poll": true,
                "allow_posting": true,
                "can_create_thread": true,
                "can_upload_attachment": true,
                "discussion_count": 0,
                "last_post_date": 0,
                "last_post_id": 0,
                "last_post_username": "",
                "last_thread_id": 0,
                "last_thread_prefix_id": 0,
                "last_thread_title": "",
                "message_count": 0,
                "min_tags": 0,
                "require_prefix": false
            }
        },
        {
            "breadcrumbs": [],
            "description": "",
            "display_in_list": true,
            "display_order": 2,
            "node_id": 5,
            "node_name": null,
            "node_type_id": "Category",
            "parent_node_id": 0,
            "title": "Perfect",
            "type_data": {}
        },
        {
            "breadcrumbs": [
                {
                    "node_id": 5,
                    "title": "Perfect",
                    "node_type_id": "Category"
                }
            ],
            "description": "",
            "display_in_list": true,
            "display_order": 2,
            "node_id": 3,
            "node_name": null,
            "node_type_id": "Forum",
            "parent_node_id": 5,
            "title": "ahmed",
            "type_data": {
                "allow_poll": true,
                "allow_posting": true,
                "can_create_thread": true,
                "can_upload_attachment": true,
                "discussion_count": 0,
                "last_post_date": 0,
                "last_post_id": 0,
                "last_post_username": "",
                "last_thread_id": 0,
                "last_thread_prefix_id": 0,
                "last_thread_title": "",
                "message_count": 0,
                "min_tags": 0,
                "require_prefix": false
            }
        },
        {
            "breadcrumbs": [],
            "description": "",
            "display_in_list": true,
            "display_order": 3,
            "node_id": 6,
            "node_name": null,
            "node_type_id": "Forum",
            "parent_node_id": 0,
            "title": "autoit",
            "type_data": {
                "allow_poll": true,
                "allow_posting": true,
                "can_create_thread": true,
                "can_upload_attachment": true,
                "discussion_count": 0,
                "last_post_date": 0,
                "last_post_id": 0,
                "last_post_username": "",
                "last_thread_id": 0,
                "last_thread_prefix_id": 0,
                "last_thread_title": "",
                "message_count": 0,
                "min_tags": 0,
                "require_prefix": false
            }
        },
        {
            "breadcrumbs": [
                {
                    "node_id": 6,
                    "title": "autoit",
                    "node_type_id": "Forum"
                }
            ],
            "description": "",
            "display_in_list": true,
            "display_order": 3,
            "node_id": 8,
            "node_name": null,
            "node_type_id": "Forum",
            "parent_node_id": 6,
            "title": "examples",
            "type_data": {
                "allow_poll": true,
                "allow_posting": true,
                "can_create_thread": true,
                "can_upload_attachment": true,
                "discussion_count": 0,
                "last_post_date": 0,
                "last_post_id": 0,
                "last_post_username": "",
                "last_thread_id": 0,
                "last_thread_prefix_id": 0,
                "last_thread_title": "",
                "message_count": 0,
                "min_tags": 0,
                "require_prefix": false
            }
        },
        {
            "breadcrumbs": [
                {
                    "node_id": 6,
                    "title": "autoit",
                    "node_type_id": "Forum"
                },
                {
                    "node_id": 8,
                    "title": "examples",
                    "node_type_id": "Forum"
                }
            ],
            "description": "",
            "display_in_list": true,
            "display_order": 3,
            "node_id": 9,
            "node_name": null,
            "node_type_id": "Forum",
            "parent_node_id": 8,
            "title": "GUI",
            "type_data": {
                "allow_poll": true,
                "allow_posting": true,
                "can_create_thread": true,
                "can_upload_attachment": true,
                "discussion_count": 0,
                "last_post_date": 0,
                "last_post_id": 0,
                "last_post_username": "",
                "last_thread_id": 0,
                "last_thread_prefix_id": 0,
                "last_thread_title": "",
                "message_count": 0,
                "min_tags": 0,
                "require_prefix": false
            }
        },
        {
            "breadcrumbs": [
                {
                    "node_id": 6,
                    "title": "autoit",
                    "node_type_id": "Forum"
                },
                {
                    "node_id": 8,
                    "title": "examples",
                    "node_type_id": "Forum"
                }
            ],
            "description": "",
            "display_in_list": true,
            "display_order": 31,
            "node_id": 10,
            "node_name": null,
            "node_type_id": "Forum",
            "parent_node_id": 8,
            "title": "windowEX",
            "type_data": {
                "allow_poll": true,
                "allow_posting": true,
                "can_create_thread": true,
                "can_upload_attachment": true,
                "discussion_count": 0,
                "last_post_date": 0,
                "last_post_id": 0,
                "last_post_username": "",
                "last_thread_id": 0,
                "last_thread_prefix_id": 0,
                "last_thread_title": "",
                "message_count": 0,
                "min_tags": 0,
                "require_prefix": false
            }
        },
        {
            "breadcrumbs": [],
            "description": "",
            "display_in_list": true,
            "display_order": 4,
            "node_id": 7,
            "node_name": null,
            "node_type_id": "Category",
            "parent_node_id": 0,
            "title": "vbs",
            "type_data": {}
        }
    ]
}

 

Link to comment
Share on other sites

So far nobody helped so either your question is not clear or you have not shown effort what you tried.

Your question seems to be create a treeview in a json similar layout and details should be shown out of an array.

If thats the question just 

Take example in help file or search forum for treeview.

Show what you tried and you will get more help and suggestions.

Link to comment
Share on other sites

22 hours ago, junkew said:

Show what you tried and you will get more help and suggestions.

;;; i will try explaying to you what i need in this example
#include <GUIConstants.au3>
Dim $arrayInfos[9][5]
$h_myTreeGUI = GUICreate("treeview", 240, 200)
$h_myTreeCTRL = GUICtrlCreateTreeView(20, 10, 200, 90)
$h_Item1 = GUICtrlCreateTreeViewItem("Windows forums", $h_myTreeCTRL)
$h_Item2 = GUICtrlCreateTreeViewItem("android forums", $h_myTreeCTRL)
$h_Item3 = GUICtrlCreateTreeViewItem("autoit development forums", $h_myTreeCTRL)
$h_SubItem1 = GUICtrlCreateTreeViewItem("softwares", $h_Item1)
$h_SubItem2 = GUICtrlCreateTreeViewItem("corses", $h_Item1)
$h_SubItem1Child1 = GUICtrlCreateTreeViewItem("download and upload", $h_SubItem1)
$h_SubItem1Child2 = GUICtrlCreateTreeViewItem("files recovry", $h_SubItem1)
$h_SubItem1Child3 = GUICtrlCreateTreeViewItem("internet download manager", $h_SubItem1Child1)
$h_SubItem1Child4 = GUICtrlCreateTreeViewItem("free download manager", $h_SubItem1Child1)
$h_SubItem1Child5 = GUICtrlCreateTreeViewItem("Recova", $h_SubItem1Child2)
$h_SubItem2 = GUICtrlCreateTreeViewItem("free apk", $h_Item2)
$h_SubItem3 = GUICtrlCreateTreeViewItem("autoit questions", $h_Item3)
$h_SubItem3Chiled1 = GUICtrlCreateTreeViewItem("GUI questions", $h_SubItem3)
$h_SubItem3Chiled2 = GUICtrlCreateTreeViewItem("consol Questions", $h_SubItem3)
#cs
 now what i need is to stoc this in array or any thing that allow me to get the data
because i have some sub infos
such as any forum must have data
e.g
number of threads
last post
type
etc...
this is just example
because the forums that i have is in json encoded
for that i can not use an variable in evry item
because i not know how much of variables that i have
i hope that you get what i need to
#ce

GUISetState()
While 1
    Switch GUIGetMsg()
        Case $GUI_event_close
            Exit
    EndSwitch
WEnd

 

Edited by Jos
No need to quote whole posts when not required :)
Link to comment
Share on other sites

Hi,

Here is an example of how you can do it:

 

#include <GUIConstants.au3>
#include <GuiTreeView.au3>


$h_myTreeGUI = GUICreate("treeview", 540, 500)
Global $h_myTreeCTRL = GUICtrlCreateTreeView(20, 10, 500, 290)
$Input1 = GUICtrlCreateInput("", 24, 311, 491, 21)
$Input2 = GUICtrlCreateInput("", 24, 337, 491, 21)
$Input3 = GUICtrlCreateInput("", 24, 364, 491, 21)
$Input4 = GUICtrlCreateInput("", 24, 394, 491, 21)
$Input5 = GUICtrlCreateInput("", 24, 421, 491, 21)
$Input6 = GUICtrlCreateInput("", 26, 450, 491, 21)

Global $a_Cat[100][2]
Global $a_Sub[200][3]
Global $a_Dat[200][7]

$a_Cat[0][0] = 0
$a_Sub[0][0] = 0
$a_Dat[0][0] = 0

AddLV_folder("", "Windows forums", 0)
AddLV_folder("", "android forums", 0)
AddLV_folder("", "autoit development forums", 0)


AddLV_folder("Windows forums", "softwares", 4)
AddLV_folder(4, "download and upload", 5)
AddLV_folder(4, "files recovry", 6)
AddLV_folder("Windows forums", "corses", 7)

AddLV_folder("android forums", "free apk", 8)

AddLV_folder("autoit development forums", "autoit questions", 9)
AddLV_folder(9, "GUI questions", 10)
AddLV_folder(9, "consol Questions", 11)


AddLV_Info(5,"internet download manager","internet_download manager.exe","c:\Progs\IDM\","www.test.com","Downloadmanager by Asd Fghi")
AddLV_Info(5,"free download manager","free download manager.exe","c:\Progs\FDM\","https://www.freedownloadmanager.org/","Best download manager")
AddLV_Info(6,"Recuva","Recuva.exe","c:\Progs\Recuva\","https://www.ccleaner.com/recuva","Recover deleted files")
AddLV_Info(222,"Test","test.exe","c:\test\","https://www.test.com/","Test entry for the top level data info")

Func AddLV_folder($cat_or_id, $name, $idnr)
    ;Call this function to add folder type items
    ;
    ;If $cat_or_id is empty, it will automatically create a top/root level item
    ;If $cat_or_id has a name, then the new item will be added too previously created root level item
    ;If $cat_or_id is a number, then the new item will be added to a previously created subitem
    ;
    ;$idnr - make sure that this is an unique number, it will be used to add to the subfolders
    ;$idnr is not used for the root items, use names for them instead
    ;
    ;$name = display name on the treeview

    Local $x, $found = -1, $foundId = 0, $tmp = 0, $t

    If IsNumber($cat_or_id) Then
        CW("number = " & $cat_or_id)
        For $x = 1 To $a_Sub[0][0]                        ;Search for the subcategory number
            If $cat_or_id = $a_Sub[$x][2] Then
                $found = $x
                $foundId = $a_Sub[$x][1]
                ExitLoop
            EndIf
        Next
    Else                                                 ;Search for the category name

        For $x = 1 To $a_Cat[0][0]
            If $cat_or_id = $a_Cat[$x][0] Then
                $found = $x
                $foundId = $a_Cat[$x][1]
                ExitLoop
            EndIf
        Next
    EndIf

    If $found > 0 Then
        $a_Sub[0][0] = $a_Sub[0][0] + 1        ;Place the Count of the categories into $a_Cat[0][0]
        Local $t = $a_Sub[0][0]
        $a_Sub[$t][0] = $name
        $a_Sub[$t][1] = GUICtrlCreateTreeViewItem($name, $foundId)
        $a_Sub[$t][2] = $idnr
        $t=$a_Sub[$t][1]
    Else
        $a_Cat[0][0] = $a_Cat[0][0] + 1       ;Place the Count of the categories into $a_Cat[0][0]
        Local $t = $a_Cat[0][0]
        $a_Cat[$t][0] = $name
        $a_Cat[$t][1] = GUICtrlCreateTreeViewItem($name, $h_myTreeCTRL)
        $t=$a_Cat[$t][1]
    EndIf

    GUICtrlSetState(-1, $GUI_DEFBUTTON)
    _GUICtrlTreeView_SetIcon($h_myTreeCTRL, $t, "shell32.dll", 4)
EndFunc   ;==>AddLV_folder

Func AddLV_Info($idnr, $name, $i1, $i2 = "", $i3 = "", $i4 = "")
    ;$IdNr - to which subcategory should the info be added
    ;if subcategory is not found, the new item will be created at the root level

    Local $tmp, $found = -1, $foundId
    For $x = 1 To $a_Sub[0][0]
        If $idnr = $a_Sub[$x][2] Then
            $foundId = $a_Sub[$x][1]
            $found = 1
            ExitLoop
        EndIf
    Next
    If $found < 0 Then
        $foundId = $h_myTreeCTRL
    EndIf

    $a_Dat[0][0] = $a_Dat[0][0] + 1
    $tmp = $a_Dat[0][0]
    $a_Dat[$tmp][1] = $name
    $a_Dat[$tmp][2] = GUICtrlCreateTreeViewItem($name, $foundId)
    $a_Dat[$tmp][3] = $i1
    $a_Dat[$tmp][4] = $i2
    $a_Dat[$tmp][5] = $i3
    $a_Dat[$tmp][6] = $i4
    _GUICtrlTreeView_SetIcon($h_myTreeCTRL, $a_Dat[$tmp][2], "shell32.dll", 1)
EndFunc   ;==>AddLV_Info

GUISetState()

While 1
    $gmsg=GUIGetMsg()
    Switch $gmsg
        Case $GUI_event_close
            Exit
        Case Else
            for $x=1 to $a_Dat[0][0]
                If $gmsg=$a_Dat[$x][2] Then
                    GUICtrlSetData ($Input1,$a_Dat[$x][1])                          ;this line is used internaly (LV item name)
                    GUICtrlSetData ($Input2,$a_Dat[$x][2])                          ;this line is used internaly (LV item id)
                    GUICtrlSetData ($Input3,$a_Dat[$x][3])  ;The actual info starts here
                    GUICtrlSetData ($Input4,$a_Dat[$x][4])
                    GUICtrlSetData ($Input5,$a_Dat[$x][5])
                    GUICtrlSetData ($Input6,$a_Dat[$x][6])
                EndIf
            Next
    EndSwitch
WEnd

Func CW($txt)
    ConsoleWrite($txt & @CRLF)
EndFunc   ;==>CW

 

P.S. there are no array limit checks, add them if needed.

Edited by Dan_555

Some of my script sourcecode

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...