Jump to content

ListView - Add items in a loop


 Share

Go to solution Solved by mikell,

Recommended Posts

So since I'm playing with listview now I been trying this

Func Test()
    Local $LF_Count = 1
    Do
        Eval("ïtem" & $LF_Count) = GUICtrlCreateListViewItem("item" & $LF_Count & "|Testing", $listview)
        $LF_Count = $LF_Count + 1
    Until $LF_Count > 9
    $item5 =  GUICtrlCreateListViewItem("erhmz" & $LF_Count & "|testing", $listview)
    ;$item1 = GUICtrlCreateListViewItem("item1|test", $listview)
EndFunc

As you probably see it will error out on the Eval line, however I tried this as well

Func Test()
    Local $LF_Count = 1
    Do
                Local $LF_Input = Eval("ïtem" & $LF_Count) 
                $LF_Input = GUICtrlCreateListViewItem("item" & $LF_Count & "|" & $LF_Input, $listview)
        $LF_Count = $LF_Count + 1
    Until $LF_Count > 9
    $item5 =  GUICtrlCreateListViewItem("erhmz" & $LF_Count & "|testing", $listview)
    ;$item1 = GUICtrlCreateListViewItem("item1|test", $listview)
EndFunc

I added the line $item5 to see if it actually got named like that, however it seems it's not? is there any method to do this on a proper way?

I know I could just create item1 till item9 in a row, however I like it a little bit more clean :)

Anyone knows?

Edited by Hawkysoft
Link to comment
Share on other sites

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
    Local $listview, $button, $item1, $item2, $item3, $msg

    GUICreate("listview items", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)
    GUISetBkColor(0x00E0FFFF) ; will change background color

    $listview = GUICtrlCreateListView("col1 |col2", 10, 10, 200, 150);,$LVS_SORTDESCENDING)
    $button = GUICtrlCreateButton("Value?", 75, 170, 70, 20)
;~  $item1 = GUICtrlCreateListViewItem("item2|col22|col23", $listview)

    GUISetState()

    $count = Random(1, 10, 1)
    Local $Lv[$count+1]

    For $i = 0 To $count -1
        $Lv[$i] = GUICtrlCreateListViewItem($i & '|' & @UserName , $listview)
    Next

    Do
        $msg = GUIGetMsg()

        Select
            Case $msg = $button
                MsgBox(0, "listview item", GUICtrlRead(GUICtrlRead($listview)), 2)
            Case $msg = $listview
                MsgBox(0, "listview", "clicked=" & GUICtrlGetState($listview), 2)
        EndSelect
    Until $msg = $GUI_EVENT_CLOSE
EndFunc   ;==>Example

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

  • Solution

I suppose you were trying to do something like this

GUICreate("listview items", 220, 250, 100, 200)
$listview = GUICtrlCreateListView("col1 |col2", 10, 10, 200, 150)
GUISetState()

For $i = 0 To 9
    Assign("item" & $i, GUICtrlCreateListViewItem($i & '|' & @UserName , $listview) )
Next

Msgbox(0,"", GUICtrlRead($item5))
Msgbox(0,"", GUICtrlRead(Eval("item6")))

But  Xenobiologist's solution using an array is by far a much better one  :)

Link to comment
Share on other sites

I suppose you were trying to do something like this

GUICreate("listview items", 220, 250, 100, 200)
$listview = GUICtrlCreateListView("col1 |col2", 10, 10, 200, 150)
GUISetState()

For $i = 0 To 9
    Assign("item" & $i, GUICtrlCreateListViewItem($i & '|' & @UserName , $listview) )
Next

Msgbox(0,"", GUICtrlRead($item5))
Msgbox(0,"", GUICtrlRead(Eval("item6")))

But  Xenobiologist's solution using an array is by far a much better one  :)

 

Hmm still doesn't work for some reason when I try to replace a line/value

Func Test()
    For $i = 1 To 9
        Assign("item" & $i, GUICtrlCreateListViewItem("item" & $i & "|Testing", $listview))
    Next
    $item5 =  GUICtrlCreateListViewItem("erhmz|testing", $listview)
EndFunc

when $item5 get's added it just adds another line on the bottom instead of updating $item5 so it seems that there isn't an actual $item5 called at the assign part?

Link to comment
Share on other sites

HawkySoft,

when $item5 get's added it just adds another line on the bottom instead of updating $item5 so it seems that there isn't an actual $item5 called at the assign part?

 

If you are trying to change an existing item use _GUICtrlListView_SetItemText.

edit: Also, use an array as shown in Xeno's example.  It will save you headaches later.

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

HawkySoft,

 

If you are trying to change an existing item use _GUICtrlListView_SetItemText.

edit: Also, use an array as shown in Xeno's example.  It will save you headaches later.

Epic failure, thanks mate and you again as well mikell

Edited by Hawkysoft
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...