Jump to content
Sign in to follow this  

Listview Items back to Array location.

Recommended Posts


I have created a listview from an array, now would like to minipulate the array information by using the information displayed in the list view.

for example, I have an array that is 100x20.

each row has 20 items, and there are 100 rows.

I see all of the items in the listview windows, as read in from the array.

Now I would like to move rows of the information up or down in reference to the order it is displayed, and as I do this, I would like to see the array get updated with the movement of items also.

I use the _GUICtrlListView_GetSelectedIndices, but I am not sure how I would translate that back to the actual location in the array, as in

what is the $array[?][?] parameters that I am trying to manipulate?

The other question I have is, when I use the _GUICtrlListView_AddArray, it obviously adds the entire array, but some of the items have not been populated as of yet, so I get blank rows in the listview. Is there some method that I can use to "clean up" the blanks in the listview?

thanks for you assistance, as you can tell, still new to AutoIT

Share this post

Link to post
Share on other sites

Hi, since you've given no code to work with I'm only going by guess work of your description. Here's a crude example based on your description or a least the my interpretation of your description for moving Items in the listview and also keeping the text in the array at the position of the item.

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <Array.au3>

Global $LVIT[100][20], $Col

PopulateVar($LVIT, $Col)

$Gui = GUICreate("ListView 100 Rows X 20 Columns", 800, 600)
$LV = GUICtrlCreateListView(StringTrimRight($Col, 1), 2, 2, 796, 556)
_GUICtrlListView_AddArray($LV, $LVIT)
For $i = 0 To UBound($LVIT, 2) - 1
    _GUICtrlListView_SetColumnWidth($LV, $i, $LVSCW_AUTOSIZE)
$Down = GUICtrlCreateButton("Move Selected Down", 10, 566, 150, 25)
$Up = GUICtrlCreateButton("Move Selected Up", 170, 566, 150, 25)
$Display = GUICtrlCreateButton("Display $LVIT Array", 330, 566, 150, 25)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
        Case $Down
            Local $Sel, $Lst
            $Sel = _GUICtrlListView_GetNextItem($LV)
            $Lst = _GUICtrlListView_GetItemCount($LV) - 1
            If $Sel < $Lst And $Sel <> -1 Then
                Local $SelTxt, $NxtTxt
                $SelTxt = _GUICtrlListView_GetItemTextArray($LV, $Sel)
                $NxtTxt = _GUICtrlListView_GetItemTextArray($LV, $Sel + 1)
                For $i = 1 To $SelTxt[0]
                    $LVIT[$Sel][$i -1] = $NxtTxt[$i]
                    $LVIT[$Sel +1][$i -1] = $SelTxt[$i]
                    _GUICtrlListView_SetItemText($LV, $Sel, $NxtTxt[$i], $i -1)
                    _GUICtrlListView_SetItemText($LV, $Sel + 1, $SelTxt[$i], $i - 1)
                    _GUICtrlListView_SetItemSelected($LV, $Sel + 1)
        Case $Up
            Local $Sel = _GUICtrlListView_GetNextItem($LV)
            If $Sel > 0 Then
                Local $SelTxt, $NxtTxt
                $SelTxt = _GUICtrlListView_GetItemTextArray($LV, $Sel)
                $PrvTxt = _GUICtrlListView_GetItemTextArray($LV, $Sel - 1)
                For $i = 1 To $SelTxt[0]
                    $LVIT[$Sel][$i -1] = $PrvTxt[$i]
                    $LVIT[$Sel -1][$i -1] = $SelTxt[$i]
                    _GUICtrlListView_SetItemText($LV, $Sel, $PrvTxt[$i], $i - 1)
                    _GUICtrlListView_SetItemText($LV, $Sel - 1, $SelTxt[$i], $i - 1)
                    _GUICtrlListView_SetItemSelected($LV, $Sel - 1)
        Case $Display
            _ArrayDisplay($LVIT, "$LVIT (ListView Item Text) Array")

Func PopulateVar(ByRef $LVIT, ByRef $Col)
    For $i = 0 To UBound($LVIT, 1) - 1
        For $j = 0 To UBound($LVIT, 2) - 1
            If $i = 0 Then $Col &= "Column " & $j & "|"
            If $j = 0 Then
                $LVIT[$i][$j] = "Item " & $i
                $LVIT[$i][$j] = "SubItem " & $i & "_" & $j
EndFunc   ;==>PopulateVar

For more help supply some code so others don't have to write code from scratch to help please.


Share this post

Link to post
Share on other sites

I want to say thank you so much, and apologize for not including my code.

I would have to say, you interpreted the exact idea of what I am needing to do to the T! :)

You are very good at understanding what I was trying to convey, and again, I apologize for not including any code.

Yes this is what I am trying to do. I will have to change it to do it "OnEvent" mode, but I think I can handle that. :)

Edited by sirjaymz

Share this post

Link to post
Share on other sites

Apologies in advance for being a super-newb. I tried to figure this out last night but I am not familiar with these functions and reading the manual did not help as much as I hoped it would. I realize you have posted a great solution here to the question I am about to ask ... Your posting is exactly on point with what I am trying to do except I am too much of a newbie to figure out how to could convert it to a single array of items from one list to a single array of items on another list that can be manipulated.

Here is what I am trying to do: I am trying to craete a shuttle list. The purpose of the program is to select scripts from one list and put them into another list in a certain user defined order to be executed in order. I plan to automate some testing with this. I am using guictrlsetdata to put the info into both lists. I see the other functions you referenced in your posted solution - but how would they apply to my situation where I have a one-dimensional array of information?

My code appears below. I am trying to figure out how to: (i) get the items that I put into my array to appear on list2 in the correct order from the array, (ii) when I hit the up button move the name of the file up, (iii) same for down, and finally, (iv) if I hit the "<--" button, remove it from the array and update list2. I can see your code does (i),(ii), and (iii). However, it is for a two dimmensional array and I am having trouble following it. My code for the things that I can get to work appears below.

Any help you could offer would be greatly appreciated.

#include <ButtonConstants.au3>

#include <GUIConstantsEx.au3>

#include <ListBoxConstants.au3>

#include <StaticConstants.au3>

#include <WindowsConstants.au3>

#Include <GuiListView.au3>

#Include <File.au3>

#include <Array.au3>

;#include <IE.au3>

#Region ### START Koda GUI section ### Form=C:\Documents and Settings\rc01712\Desktop\WFTestHarnessTool\shuttleListScriptRunner.kxf

$Form1_1 = GUICreate("Script Runner", 667, 385, 208, 159)

$List1 = GUICtrlCreateList("", 24, 64, 209, 227)

GUICtrlSetData(-1, "listString")

$Button1 = GUICtrlCreateButton("Run", 208, 304, 153, 57)

$Label1 = GUICtrlCreateLabel("Script Runner", 200, 0, 150, 33)

GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")

$List2 = GUICtrlCreateList("", 328, 64, 201, 227)

GUICtrlSetData(-1, "")

$Button2 = GUICtrlCreateButton("--->", 240, 96, 73, 33)

$Button3 = GUICtrlCreateButton("<---", 240, 152, 73, 33)

$Label2 = GUICtrlCreateLabel("Available Scripts", 48, 32, 141, 28)

GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")

$Label3 = GUICtrlCreateLabel("Scripts To Run", 360, 32, 128, 28)

GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")

$Button4 = GUICtrlCreateButton("Up", 536, 128, 49, 41)

$Button5 = GUICtrlCreateButton("Down", 536, 184, 49, 41)

$displayArray = GUICtrlCreateButton("debugArray", 504, 24, 73, 33)


#EndRegion ### END Koda GUI section ###

dim $FileList; this is used to read the files in a certain directory

func getFileNames()


If @Error=1 Then

MsgBox (0,"","No Files\Folders Found.")




Return $FileList ;returned array to be used to load file names to listview control



dim $endOfArray = ubound($FileList)


Global $LIST2ARRAY[$endOfArray]

func setList1();puts items from filelist array onto list1 in no pre-specified order

dim $a

dim $listString=""

for $a=1 to $endOfArray step 1







dim $lastElement = UBound($LIST2ARRAY)-1

func addItemList1ToList2(); used to add a selected item from list1 to list2 - does not put it in the correct order

dim $script = GUICtrlRead ($List1)






func daisyChainRun(); will be used to run selected scripts after they are properly sorted etc

;need loop code tied to array list in list view

dim $script = GUICtrlRead ($List1)

$scriptPath = @ScriptDir&"\scripts\"



While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $Button1;run button


Case $Button2;--> button


Case $Button4;up

case $Button5;down button

Case $displayArray






Edited by Jfish

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

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
Sign in to follow this