Jump to content

tree view from array


Recommended Posts

I Have the following data in an array

[0]|14

[1]|profile

[2]|process

[3]|profile1

[4]|C:\FH5\FH5.EXE

[5]|profile1

[6]|C:\FH5\PS2MAC.EXE

[7]|profile2

[8]|C:\Auto_ad\ad_info\sqlcmd.exe

[9]|profile3

[10]|C:\Program Files\Areca\areca.exe

[11]|profile4

[12]|C:\Team17\Worms World Party\wwp.exe

[13]|profile4

[14]|C:\FH5\FH5.EXE

An I am trying to get the data into a treeview with each application falling under each profile. I was trying something like.

_GUICtrlTreeViewDeleteAllItems($Treeview1)
;Read the ini to find the locations
    GUICtrlSetCursor($TreeView1, 1)
    $tree_array= _SQLite_GetTable (-1, "SELECT DISTINCT profile,process FROM profile_processes;", $aResult, $iRows, $iColumns)
    _ArrayDisplay($aResult)
;write these to the list view
    For $i = 2 To $aResult[0] step 1
    $rootitem=_GUICtrlTreeViewInsertItem($Treeview1, $aResult[$i])
                For $i = 4 To $aResult[0] step 10
                _GUICtrlTreeViewInsertItem($Treeview1, $aResult[$i],$rootitem)
                Next
    Next
    GUICtrlSetCursor($TreeView1, 2)
;working above this line

Any help would be appreciated. Oh the data is stored in a database but dont worry about that.

Link to comment
Share on other sites

Do you want one item under each profile (the item following the profile number)? Maybe something like this:

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

Opt("GUIOnEventMode", 1)

Dim $testArray[15], $temp
$testArray[0] = 14
$testArray[1] = "profile"
$testArray[2] = "process"
$testArray[3] = "profile1"
$testArray[4] = "C:\FH5\FH5.EXE"
$testArray[5] = "profile1"
$testArray[6] = "C:\FH5\PS2MAC.EXE"
$testArray[7] = "profile2"
$testArray[8] = "C:\Auto_ad\ad_info\sqlcmd.exe"
$testArray[9] = "profile3"
$testArray[10] = "C:\Program Files\Areca\areca.exe"
$testArray[11] = "profile4"
$testArray[12] = "C:\Team17\Worms World Party\wwp.exe"
$testArray[13] = "profile4"
$testArray[14] = "C:\FH5\FH5.EXE"

$GUI = GUICreate("Test GUI", 600, 600)
GUISetOnEvent($GUI_EVENT_CLOSE, "Terminate")

$TreeView = GUICtrlCreateTreeView(20, 20, 560, 560)
For $i = 1 To $testArray[0] Step 2
    $temp = GUICtrlCreateTreeViewItem($testArray[$i], $TreeView)
    _GUICtrlTreeViewInsertItem($TreeView, $testArray[$i + 1], $temp)
Next

GUISetState()

While 1
    Sleep(10)
WEnd

Func Terminate()
    Exit 0
EndFunc

Edit: Anyone else's spacing in their codebox's getting all f***ed up?

Edited by mikehunt114
IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
Link to comment
Share on other sites

Do you want one item under each profile (the item following the profile number)? Maybe something like this:

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

Opt("GUIOnEventMode", 1)

Dim $testArray[15], $temp
$testArray[0] = 14
$testArray[1] = "profile"
$testArray[2] = "process"
$testArray[3] = "profile1"
$testArray[4] = "C:\FH5\FH5.EXE"
$testArray[5] = "profile1"
$testArray[6] = "C:\FH5\PS2MAC.EXE"
$testArray[7] = "profile2"
$testArray[8] = "C:\Auto_ad\ad_info\sqlcmd.exe"
$testArray[9] = "profile3"
$testArray[10] = "C:\Program Files\Areca\areca.exe"
$testArray[11] = "profile4"
$testArray[12] = "C:\Team17\Worms World Party\wwp.exe"
$testArray[13] = "profile4"
$testArray[14] = "C:\FH5\FH5.EXE"

$GUI = GUICreate("Test GUI", 600, 600)
GUISetOnEvent($GUI_EVENT_CLOSE, "Terminate")

$TreeView = GUICtrlCreateTreeView(20, 20, 560, 560)
For $i = 1 To $testArray[0] Step 2
    $temp = GUICtrlCreateTreeViewItem($testArray[$i], $TreeView)
    _GUICtrlTreeViewInsertItem($TreeView, $testArray[$i + 1], $temp)
Next

GUISetState()

While 1
    Sleep(10)
WEnd

Func Terminate()
    Exit 0
EndFunc

Edit: Anyone else's spacing in their codebox's getting all f***ed up?

Yes thats what I was trying to do.

Do you think I am coming from this at the wrong angle if I want all the processes for a particular process to fall under one treenode.So for example profile 1 would contain C:\FH5\FH5.EXE & C:\FH5\PS2MAC.EXE

Thank you for your help.

Link to comment
Share on other sites

That's a bit trickier, but if you just work it out, arrays will do the job well. See if this makes sense:

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

Opt("GUIOnEventMode", 1)

Dim $testArray[15], $ProfileArray[1], $j = 0, $k = 0, $match = False, $text = ""
$testArray[0] = 14
$testArray[1] = "profile"
$testArray[2] = "process"
$testArray[3] = "profile1"
$testArray[4] = "C:\FH5\FH5.EXE"
$testArray[5] = "profile1"
$testArray[6] = "C:\FH5\PS2MAC.EXE"
$testArray[7] = "profile2"
$testArray[8] = "C:\Auto_ad\ad_info\sqlcmd.exe"
$testArray[9] = "profile3"
$testArray[10] = "C:\Program Files\Areca\areca.exe"
$testArray[11] = "profile4"
$testArray[12] = "C:\Team17\Worms World Party\wwp.exe"
$testArray[13] = "profile4"
$testArray[14] = "C:\FH5\FH5.EXE"

$GUI = GUICreate("Test GUI", 600, 600)
GUISetOnEvent($GUI_EVENT_CLOSE, "Terminate")

$TreeView = GUICtrlCreateTreeView(20, 20, 560, 560)
For $i = 1 To $testArray[0] Step 2
    $text = $testArray[$i + 1]      ;the desired text is always the next item after the profile name
    For $j = 0 To UBound($ProfileArray) - 1         ;check through the profile array to see if one of the same name is already made
        If $testArray[$i] == GUICtrlRead($ProfileArray[$j], 1) Then     ;advanced GUICtrlRead to get the TreeViewItem text
            $match = True           ;for later
            _GUICtrlTreeViewInsertItem($TreeView, $text, $ProfileArray[$j])     ;if a match is found, insert the item there
            ExitLoop
        Else
            $match = False      ;no match found
        EndIf
    Next
    If $match = False Then      ;If no match found, create a new one, and insert the item afterwards
        ReDim $ProfileArray[$k + 1]     ;keep increasing the size of the profile array each time we add an item
        $ProfileArray[$k] = GUICtrlCreateTreeViewItem($testArray[$i], $TreeView)
        _GUICtrlTreeViewInsertItem($TreeView, $text, $ProfileArray[$k])
        $k += 1
    EndIf
Next
GUISetState()

While 1
    Sleep(10)
WEnd

Func Terminate()
    Exit 0
EndFunc

Edit: Added comments.

Edited by mikehunt114
IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
Link to comment
Share on other sites

That's a bit trickier, but if you just work it out, arrays will do the job well. See if this makes sense:

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

Opt("GUIOnEventMode", 1)

Dim $testArray[15], $ProfileArray[1], $j = 0, $k = 0, $match = False, $text = ""
$testArray[0] = 14
$testArray[1] = "profile"
$testArray[2] = "process"
$testArray[3] = "profile1"
$testArray[4] = "C:\FH5\FH5.EXE"
$testArray[5] = "profile1"
$testArray[6] = "C:\FH5\PS2MAC.EXE"
$testArray[7] = "profile2"
$testArray[8] = "C:\Auto_ad\ad_info\sqlcmd.exe"
$testArray[9] = "profile3"
$testArray[10] = "C:\Program Files\Areca\areca.exe"
$testArray[11] = "profile4"
$testArray[12] = "C:\Team17\Worms World Party\wwp.exe"
$testArray[13] = "profile4"
$testArray[14] = "C:\FH5\FH5.EXE"

$GUI = GUICreate("Test GUI", 600, 600)
GUISetOnEvent($GUI_EVENT_CLOSE, "Terminate")

$TreeView = GUICtrlCreateTreeView(20, 20, 560, 560)
For $i = 1 To $testArray[0] Step 2
    $text = $testArray[$i + 1]      ;the desired text is always the next item after the profile name
    For $j = 0 To UBound($ProfileArray) - 1         ;check through the profile array to see if one of the same name is already made
        If $testArray[$i] == GUICtrlRead($ProfileArray[$j], 1) Then     ;advanced GUICtrlRead to get the TreeViewItem text
            $match = True           ;for later
            _GUICtrlTreeViewInsertItem($TreeView, $text, $ProfileArray[$j])     ;if a match is found, insert the item there
            ExitLoop
        Else
            $match = False      ;no match found
        EndIf
    Next
    If $match = False Then      ;If no match found, create a new one, and insert the item afterwards
        ReDim $ProfileArray[$k + 1]     ;keep increasing the size of the profile array each time we add an item
        $ProfileArray[$k] = GUICtrlCreateTreeViewItem($testArray[$i], $TreeView)
        _GUICtrlTreeViewInsertItem($TreeView, $text, $ProfileArray[$k])
        $k += 1
    EndIf
Next
GUISetState()

While 1
    Sleep(10)
WEnd

Func Terminate()
    Exit 0
EndFunc

Edit: Added comments.

Just wanted to say Thanks for helping

Im going to have to read this one through a few times to get my head round it (probably a few thousand times).

again cheers

Link to comment
Share on other sites

It took me a few minutes to wrap my own head around it :whistle:

Cheers.

IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...