Sign in to follow this  
Followers 0
FireLordZi

Store items in an array

13 posts in this topic

How do I store all the items that are in my third column into an array so after I delete every item in the listview I can reload the items like they were never deleted?


While Alive() {
	 DrinkWine();
}
AutoIt Programmer

Share this post


Link to post
Share on other sites



Sorry but.... i dont undestand what do you want to get ? You want to keep only third column of listview, and when you erase whole listview you want to reload only the data from 3 column? Im right??


Share this post


Link to post
Share on other sites

Correct.


While Alive() {
	 DrinkWine();
}
AutoIt Programmer

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

It will be hard to make without any cells selected.... hmmm... sory but i think i coud not help :D

But i will try and when i'll get something i'll post it.

Edited by Uriziel01

Share this post


Link to post
Share on other sites

my listview isn't multi-select anyway. i was thinking it could be done in a for next loop and store in an array with however many items are in the 3rd listview column, then delete all items in listview, and after that reload the items back into the thrid column.


While Alive() {
	 DrinkWine();
}
AutoIt Programmer

Share this post


Link to post
Share on other sites

This will not be better ??

_GUICtrlListView_DeleteColumn($ListView, 0)
_GUICtrlListView_DeleteColumn($ListView, 1)

It will delete only 2 from 3 columns :D


Share this post


Link to post
Share on other sites

This will not be better ??

_GUICtrlListView_DeleteColumn($ListView, 0)
_GUICtrlListView_DeleteColumn($ListView, 1)

It will delete only 2 from 3 columns :D

Too bad I don't have the latest version. I already thought of that and I can't. I can't upgrade either until I finish the script I'm workng on....

While Alive() {
	 DrinkWine();
}
AutoIt Programmer

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

somebody have idea why GUICtrlSetState ( controlID, $GUI_CHECKED ) dont work on ListViewItem ?? Some new bug in new version ? Or meaby im doing something wrong ?

SciTe help says "$GUI_CHECKED Radio, Checkbox or ListViewItem will be checked. "

p.s-but can't you add only UDF #include <GuiListView.au3> from new version ?

Edited by Uriziel01

Share this post


Link to post
Share on other sites

somebody have idea why GUICtrlSetState ( controlID, $GUI_CHECKED ) dont work on ListViewItem ?? Some new bug in new version ? Or meaby im doing something wrong ?

SciTe help says "$GUI_CHECKED Radio, Checkbox or ListViewItem will be checked. "

p.s-but can't you add only UDF #include <GuiListView.au3> from new version ?

You probably need to start your own thread next time for a question totally different from my topic.


While Alive() {
	 DrinkWine();
}
AutoIt Programmer

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

would it not be preferable to store items to be entered in third column into an array at time of data entry?

anyway here's an example of reading third column items into an array

#include <GUIConstantsEx.au3>
Local $listview, $msg, $i = 1, $iflag = 0
Dim $aItem[1], $aCol3[1]
Dim $lvitem[5]=["item1|col12|col13","item2|col22|col23", _
"item3|col32|col33","item4|col42|col43","item5|col52|col53"]

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

For $element In $lvitem
    $aSize = UBound($aItem)
    Switch $iflag
        Case 0
            $iflag = 1
        Case 1
            $aSize += 1
            ReDim $aItem[$aSize]
    EndSwitch
    $aItem[$aSize-1] = GUICtrlCreateListViewItem($element, $listview)
Next

GUISetState()

For $element In $aItem
    GUICtrlSetState($element, $GUI_FOCUS) ; to answer the 'thread hijacking' question, the item must be focused first then read (or checked)
    Local $aArray = StringSplit(GUICtrlRead(GUICtrlRead($listview)),"|")
    ReDim $aCol3[$i]
    $aCol3[$i-1] = $aArray[$aArray[0]] ; changed from fixed $aArray[3] to $aArray[$aArray[0]] for last column
    $i += 1
Next

For $element In $aCol3 ; array contains third column items
    ConsoleWrite($element&@LF)
Next

Do
    $msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE
Exit
Edited by rover

I see fascists...

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

So what is $lvitem anyway? Is it the listview items? If so, can I use my ini to represent it instead of a bunch of arrays?

Edit: Nvm, I'm having tons of problems with it

Edited by FireLordZi

While Alive() {
	 DrinkWine();
}
AutoIt Programmer

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

So what is $lvitem anyway? Is it the listview items? If so, can I use my ini to represent it instead of a bunch of arrays?

Edit: Nvm, I'm having tons of problems with it

$lvitem array is used for an example of control creation on the fly to allow adding listview items as needed

and storing the control ids in an array.

you can remove the 'For $element In $lvitem' loop

and call the code inside it in a function and replace '$element' with your iniread contents

pseudocode

Global $iflag = 0

; would be your variable with string elements assembled from ini file with '|' delimiter
$var = "item1|col12|col13"

_AddLVItem($var)

Func _AddLVItem($item)
    Local $aSize = UBound($aItem)
    Switch $iflag ; prevents redimming array when size is one element
        Case 0
            $iflag = 1
        Case 1
            $aSize += 1
            ReDim $aItem[$aSize]
    EndSwitch
    $aItem[$aSize-1] = GUICtrlCreateListViewItem($item, $listview)
EndFunc
Edited by rover

I see fascists...

Share this post


Link to post
Share on other sites

somebody have idea why GUICtrlSetState ( controlID, $GUI_CHECKED ) dont work on ListViewItem ?? Some new bug in new version ? Or meaby im doing something wrong ?

SciTe help says "$GUI_CHECKED Radio, Checkbox or ListViewItem will be checked. "

p.s-but can't you add only UDF #include <GuiListView.au3> from new version ?

From help file

State of a "listviewitem" control can be changed if the associated "listview" control has been created with an extended style $LVS_EX_CHECKBOXES

Example:

#include <GuiConstants.au3>

Global $aLV_Items[11]
$aLV_Items[0] = 10

$Gui = GUICreate("Test", 300, 200)

$ListView = GUICtrlCreateListView("Items     ", 20, 15, 260, 150, BitOR($LVS_EDITLABELS, $LVS_REPORT), $LVS_EX_CHECKBOXES + $WS_EX_CLIENTEDGE)

For $i = 1 To $aLV_Items[0]
    $aLV_Items[$i] = GUICtrlCreateListViewItem("Item" & $i, $ListView)
Next

$Check_Btn =GUICtrlCreateButton("Check all", 20, 170, 70, 25)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
    Case $GUI_EVENT_CLOSE
        ExitLoop
    Case $Check_Btn
        CheckUncheck(GUICtrlRead($Check_Btn))
    EndSwitch
WEnd

Func CheckUncheck($State)
    Local $Flag, $i
    If $State = "Check all" Then
        GUICtrlSetData($Check_Btn, "Uncheck all")
        $Flag = $GUI_CHECKED
    Else
        $Flag = $GUI_UNCHECKED
        GUICtrlSetData($Check_Btn, "Check all")
    EndIf
    
    For $i = 1 To $aLV_Items[0]
        GUICtrlSetState($aLV_Items[$i], $Flag)
    Next
EndFunc

:)

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  
Followers 0