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 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!
    • By thedemons
      Introduction
      ImGui is a popular library written by ocornut, it can make awesome user interface based on directx. It is being used by many big apps/games.  The UI is nice and flexible, easy to use because of frame-by-frame drawing. So I decided to convert the entire ImGui library to AutoIt
      At first it's just an experiment, i converted some basic draw functions of imgui, compile to a dll, then using DllCall in autoit to call the functions. I was testing to see how much FPS i can get in autoit, and i was expected a low FPS, since autoit is slow. Suprisingly, the FPS turned out to be so high, it works really fast, even when drawing 1000 buttons at the same time. Features
      More than +270 functions converted from ImGui (compiled dll). Has 90% of the capability of what you can do in C++; Usable ImGuiIO and ImGuiStyle, so you can set whatever configurations you like. Preview
          
      Usage
      #include <WinAPI.au3> #include "ImGui.au3" ; Create a window Local $hwnd = _ImGui_GUICreate("AutoIt ImGui", 1024, 768) _WinAPI_ShowWindow($hwnd) ; Set style color _ImGui_StyleColorsLight() ;~ _ImGui_StyleColorsDark() Local $f_value = 5 While 1 ; when the user click close button on the window, this will return false if Not _ImGui_PeekMsg() Then Exit ; must call _ImGui_BeginFrame() _ImGui_Begin("Another window") _ImGui_Text("Hello there..") If _ImGui_Button("click me") Then $f_value = 5 _ImGui_SliderFloat("slider", $f_value, 2, 20) If _ImGui_IsItemHovered() Then _ImGui_ToolTip("what r u doing?") _ImGui_End() ; must call _ImGui_EndFrame() Wend  
      Remark
      Most of the functions were converted automatically. I haven't tested all of them yet, if some function doesn't work for you, please tell me. Still missing some features of ImGui, please tell me if you needed any. Run \tools\imgui-au3-setup.au3 to add _ImGui functions to SciTE auto-complete. Source Code
      Require: DirectX GitHub: imgui-autoit
    • By Colduction
      Hi dear friends!, i'm sorry for creating a new thread (a new problem), i have over than 9 lists that i want to combine them to be this (in this example, there are 3 test files):


      I've written a little code for splitting main information, but i really confused how to make results as "Output.txt", here is that code:
       
      $sRegex_1 = StringRegExp(FileRead("1.txt"), '(?s:(?<=\=\=\r\n)(.*?)(?=\r\n\=\=))', 3) $sRegex_2 = StringRegExp(FileRead("2.txt"), '(?s:(?<=\=\=\r\n)(.*?)(?=\r\n\=\=))', 3) $sRegex_3 = StringRegExp(FileRead("3.txt"), '(?s:(?<=\=\=\r\n)(.*?)(?=\r\n\=\=))', 3) For $i = 0 To UBound($sRegex_1) - 1 ConsoleWrite($sRegex_1[$i] & @CRLF) For $j = 0 To UBound($sRegex_2) - 1 ConsoleWrite($sRegex_2[$j] & @CRLF) For $k = 0 To UBound($sRegex_3) - 1 ConsoleWrite($sRegex_3[$k] & @CRLF) Next Next Next  
    • By nacerbaaziz
      hello evrybody
      here is an example about how to split your texts using a delimiter with the ability to select how much of delimiters shows in each colum  with $i_number
      e.g
      you have a long text and you want to split it in an array
      that evry colum have a number (n) of lines
      i made a function that do that for you
      just call it with a three params
      $s_text
      your text
      $i_number
      the number that you want to put in each col
      $s_siparator
      the siparator
      default is "|"
      here is the function with example
      i hope that it will be useful for you
       
      ****
       
      #include <Array.au3> $s_txt = "some text1some text2|some text3|some text4|some text5|some text6" $array = splitText($s_txt, 2) _ArrayDisplay($array) Func splitText($s_text, $i_number, $s_siparator = "|") Local $a_TXT = StringSplit($s_text, $s_siparator) Local $a_Return[$a_TXT[0] + 1] If ($a_TXT[0] <= $i_number) Or ($i_number <= 0) Then ReDim $a_Return[2] $a_Return[0] = 1 $a_Return[1] = $s_text Return $a_Return EndIf Local $i_Processed = 1, $i_arrayProcessed = 1 Do For $i = $i_Processed To ($i_Processed + $i_number) - 1 If ($a_TXT[0] < $i) Then ExitLoop If Not ($a_Return[$i_arrayProcessed]) Then $a_Return[$i_arrayProcessed] = $a_TXT[$i] Else $a_Return[$i_arrayProcessed] &= $s_siparator & $a_TXT[$i] EndIf $i_Processed += 1 Next $i_arrayProcessed += 1 Until ($a_TXT[0] < $i_Processed) ReDim $a_Return[$i_arrayProcessed] $a_Return[0] = $i_arrayProcessed - 1 Return $a_Return EndFunc ;==>splitText
      accept my greetings
      thanks to
      @Dan_555
      for his notes
       
×
×
  • Create New...