Jump to content
MesterPerfect

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": {}
        }
    ]
}

 

Share this post


Link to post
Share on other sites

@MesterPerfect

you can visit this thread to know how to use the json in autoit

 

 

 can help you if your forum have at max 2 sec

i mean

main forum / sub

because you can do that using the 2d array

but am sorry i can not do more

i hope any one here can help you

i

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Posted (edited)
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 :)

Share this post


Link to post
Share on other sites
Posted (edited)

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

~Dan~ :Emu.Zone now with Desktop Pets / DeskMates - (Bugfixed UniScrMate 4.1)

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By TXTechie
      Hello Everyone,
      I've developed my own GUI using AutoIt and I'm allowing users to minimize the GUI, but I also want to include some kind of timer so that it will automatically restore the GUI after something like 30 minutes or an hour. However, I also want them to be able to manually restore the GUI by clicking the application's icon in the taskbar.
      I've searched through the forums, but I'm not sure how to get started.
      Any ideas or functions to research are appreciated!
      Regards,
      TX Techie
    • By jcpetu
      Hi people, I'm trying to dynamically populate a TreeView based on a script from Water that I modified for my needs. but I can't figured it out how to make it work.
      Here what I have in case anyone can help me, thanks in advance:
      #include <array.au3> #include <GUIConstantsEx.au3> #include <GuiTreeView.au3> Local $aTV1[14][3] = [ _ ['1', 'Text 1', -1], _ ;-1 idicates it's an index item ['2', 'Text 2',-1], _ ['3', 'Text 3',-1], _ ['1-1', 'Text 1-1',0], _ ['1-2', 'Text 1-2',0], _ ['2-1', 'Text 2-1',0], _ ['2-2', 'Text 2-2',0], _ ['2-1-1', 'Text 2-1-1',0], _ ['2-1-2', 'Text 2-1-2',0], _ ['2-1-2-1', 'Text 2-1-2-1',0], _ ['2-1-2-1-1', 'Text 2-1-2-1-1',0], _ ['3-1', 'Text 3-1',0], _ ['3-1-1', 'Text 3-1-1',0], _ ['3-1-1-1', 'Text 3-1-1-1',0]] ;_ArrayDisplay($aTV1) Local $Gui = GUICreate('TreeView Example', 500, 600) Local $tv = GUICtrlCreateTreeView(10, 30, 450, 550) GUISetState() _pop_treeview($tv, $aTV1) While 1 Switch GUIGetMsg() Case $gui_event_close Exit EndSwitch WEnd Func _pop_treeview($hTV, $array) Local $TimeInitial = TimerInit(), $Hours, $Mins, $Secs, $item _ArraySort($array, 0, 0, 0, 0) ;------------------------- sort Ascending on column 0 ;_ArrayDisplay($array) $idxroot = _GUICtrlTreeView_Add($hTV, 0, "index") For $i = 0 To UBound($array) - 1 ConsoleWrite("$array[" & $i & "][" & 0 & "] = " & $array[$i][0] & @CRLF) If $array[$i][0] = '' Then ExitLoop ;--------------- Exit at first empty element $item = '' If $array[$i][2] = -1 Then ;------------------------ Add root element _GUICtrlTreeView_AddChild($hTV, $idxroot, $array[$i][1]) Else $item = StringLeft($array[$i][0], StringInStr($array[$i][0], "-", 1, -1) - 1) ConsoleWrite("$item = " & $item & @CRLF) $Found = _ArrayBinarySearch($array, $item, 0, 0, 0) ;search on column 0 Switch $Found Case 0 ;----------------------------------- Value wasn't found in array ConsoleWrite("Item NOT found @error= " & @error & @CRLF) Case Else ConsoleWrite("Item found " & @CRLF) _GUICtrlTreeView_AddChild($hTV, $Found, $array[$i][1]) EndSwitch EndIf Next _GUICtrlTreeView_Expand($hTV) EndFunc ;==>_pop_treeview  
    • By Jangal
      Hello friends
      This app is slow
      How to increase its speed?
       
      #include <Array.au3> #include <StringConstants.au3> #include <File.au3> #include <String.au3> Global $aWord[][2]  = [[1, "google"],[2,"hello"]]


        Global $sFileName = @ScriptDir & "\1.txt" ; 2MB Text File Local $sFileRead = FileRead($sFileName) Local $res = StringRegExp($sFileRead, "(*UCP)\b[\pL\d]{2,}", 3) _ArrayDisplay($res)   for $sWord in $res     $iIndex = _ArraySearch($aWord, $sWord, 0, 0, 0, 0, 1, 2)     ;MsgBox(0,0,$iIndex)     if $iIndex == -1 Then         Local $aFill = [[0,$sWord]]         _ArrayAdd($aWord,$aFill)        ;      Else         $aWord[$iIndex][0] +=1     EndIf   Next _ArrayDisplay($aWord)

      1.txt
    • By Rskm
      Hi, recently i created a GUI for some calculations in AutoIT.  The GUI has 2 tabs and on the first tab, it has few inputboxes where i use to click with mouse and start entering the inputs. i recently made some changes in the position of these textboxes. I made this by changing the autoit code file instead of making changes in KODA. Now i cannot click inside these textboxes with mouse. However, i can use TAB key to cycle through/enter input in these input boxes. what could have made the inputboxes not responding to mouseclicks. thanks
    • By TheDcoder
      Hi everyone,
      I am bit stumped as to why I am not able to set the time in the Date control
      #include <DateTimeConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Example() Func Example() GUICreate("My GUI get date", 200, 200, 800, 200) Local $idDate = GUICtrlCreateDate("1953/04/25", 10, 10, 185, 20, $DTS_TIMEFORMAT) ; to select a specific default format Local $sStyle = "HH:mm:ss" GUICtrlSendMsg($idDate, $DTM_SETFORMATW, 0, $sStyle) ; Set time Local $iRet = GUICtrlSetData($idDate, '13:33:37') ConsoleWrite('GUICtrlSetData returned ' & ($iRet = 1 ? 'success' : 'failure') & @CRLF) GUISetState(@SW_SHOW) ; Loop until the user exits. While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd MsgBox($MB_SYSTEMMODAL, "Time", GUICtrlRead($idDate)) EndFunc ;==>Example The documentation for GUICtrlSetData clearly mentions that it uses the same format as GUICtrlRead:
      But I get failure
      What gives?
      Thanks for the help in advance!
×
×
  • Create New...