Sign in to follow this  
Followers 0
FaT3oYCG

List View Functions

2 posts in this topic

#1 ·  Posted (edited)

Hi I'm not new to autoit i have been using it for a while but the ammount of different features that it has means that not all people will be able to learn it all which is why i require your help.

My problem is that i need to know which item is currently selected in the list and be able to change some of the attributs in each row by getting and setting that data.

So basically a rundown of the functions that i need is:

1. How to determine the currently selected item without looping through all of the items (if possible)

2. how to get the whole row of data for that item (like when you add an item or initiate the list)

3. how to set the whole row of data for that item (like when you add an item or initiate the list)

here is my code if it helps

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

#Region ### START Koda GUI section ### Form=
$Main = GUICreate("CSPSP Guns.txt Creator / Editor", 751, 354, 207, 162)
$lstGunsList = GUICtrlCreateListView("quad|damage|delay|spread|clip|#ofclips|reloaddelay|walkingspeed|bulletspeed|money|type|name", 0, 28, 750, 290)
$lblTitle = GUICtrlCreateLabel("CSPSP Guns.txt Creator / Editor", 4, 4, 160, 17)
$lblGunNumber = GUICtrlCreateLabel("Number Of Guns:", 468, 8, 86, 17)
$lblGunNumberDisplay = GUICtrlCreateLabel("0", 556, 8, 22, 17)
$btnEdit = GUICtrlCreateButton("Edit", 496, 320, 81, 29)
$btnDelete = GUICtrlCreateButton("Delete", 580, 320, 81, 29)
$btnAdd = GUICtrlCreateButton("Add", 412, 320, 81, 29)
$btnOpen = GUICtrlCreateButton("Open", 582, 4, 81, 21)
$btnSave = GUICtrlCreateButton("Save", 666, 4, 81, 21)
$btnExit = GUICtrlCreateButton("Exit", 666, 320, 81, 29)
$inptGunData = GUICtrlCreateInput("", 4, 324, 405, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$varGunInformationLine = "quad damage delay spread clip #ofclips reloaddelay walkingspeed bulletspeed money type name"
$varCurrentPath = @ScriptDir & "Guns.txt"

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $btnEdit
    ; need help
        Case $btnDelete
    ; not implemented - i have found the func just need help as stated above current item thing
        Case $btnAdd
    ; not implemented - i have found the func just need help as stated above current item thing
        Case $btnOpen
            $retVal = FileOpenDialog("CSPSP Guns.txt Creator / Editor File Select", @ScriptDir, "Text Documents (*.txt)", 1, "Guns.txt")
            If @error Then
                MsgBox(64, "Information.", "No File chosen.")
            Else
        ;open file read line by line replace spaces with | and add to list.
                GUICtrlDelete($lstGunsList)
                $lstGunsList = GUICtrlCreateListView("quad|damage|delay|spread|clip|#ofclips|reloaddelay|walkingspeed|bulletspeed|money|type|name", 0, 28, 750, 290)
                GUICtrlSetData($lblGunNumberDisplay, "0")
                $varCurrentPath = $retVal
                $varGuns = FileOpen($retVal, 0)
                While @error <> -1 Or @error <> 1
                    $varCurrentGun = FileReadLine($varGuns)
                    If @error = -1 Then ExitLoop
                    If StringIsDigit(StringLeft($varCurrentGun, 1)) Or StringIsInt(StringLeft($varCurrentGun, 2)) And StringLen($varCurrentGun) <> 2 Then
                        $varCurrentGun = StringReplace($varCurrentGun, " ", "|")
                        GUICtrlCreateListViewItem($varCurrentGun, $lstGunsList)
                        GUICtrlSetData($lblGunNumberDisplay, GUICtrlRead($lblGunNumberDisplay) + 1)
                    EndIf
                WEnd
                FileClose($varGuns)
            EndIf
        Case $btnSave
            _SaveFunc()
        Case $btnExit
            _ExitFunc()
        Case $GUI_EVENT_CLOSE
            _ExitFunc()
    EndSwitch
WEnd

Func _ExitFunc()
    $retVal = MsgBox(52, "Warning!", "Are You Sure You Want To Exit?")
    If $retVal = 6 Then
        $retVal = MsgBox(36, "Warning!", "Save Now?")
        If $retVal = 6 Then
            _SaveFunc()
            Exit
        Else
            Exit
        EndIf
    EndIf
EndFunc;==>_ExitFunc

Func _SaveFunc()
    $varNumberOfGuns = GUICtrlRead($lblGunNumberDisplay)
    $varGuns = FileOpen($varCurrentPath, 2)
    FileWriteLine($varGuns, $varNumberOfGuns)
    For $i = 1 To $varNumberOfGuns
        $varCurrentGun =; need to get the item and manipulate the data
        FileWriteLine($varGuns, $varCurrentGun)
    Next
    FileWriteLine($varGuns ,$varGunInformationLine)
    FileClose($varGuns)
    MsgBox(64, "Information.", "Your Changes Have Been Saved.")
EndFunc;==>_SaveFunc

here is a sample guns.txt file

28
0 25 300 0.0 0 0 0 2.0 0.0 0 2 Slit-Throat
1 10 100 0.0 20 4 2100 1.2 1.0 400 1 GLOCK
2 15 100 0.0 12 6 1900 1.2 1.0 500 1 USP
3 20 100 0.0 13 5 2000 1.2 1.0 600 1 P228
4 30 100 0.0 7 6 1600 1.2 1.0 650 1 DEAGLE
5 15 100 0.0 20 6 2200 1.2 1.0 750 1 FIVESEVEN
6 15 100 0.0 30 5 3800 1.2 1.0 1000 1 ELITE
7 18 1100 0.65 8 5 4000 1.0 1.0 1700 0 M3
8 18 250 0.50 7 5 2500 1.0 1.0 3000 0 XM1014
9 11 85 0.55 30 5 1600 1.1 1.0 1250 0 TMP
10 11 85 0.55 30 4 1850 1.1 1.0 1700 0 MAC10
11 15 90 0.40 30 5 1700 1.1 1.0 1500 0 MP5
12 20 100 0.35 25 5 1900 1.1 1.0 1400 0 UMP
13 12 70 0.40 50 3 1900 1.1 1.0 2350 0 P90
14 20 65 0.40 25 4 2000 1.0 1.0 2250 0 FAMAS
15 25 90 0.40 35 4 1900 1.0 1.0 2000 0 GALIL
16 70 1200 0.30 10 10 1500 1.2 2.0 2750 0 SCOUT
17 25 100 0.25 30 4 2100 1.0 1.0 3100 0 M4A1
18 30 100 0.35 30 4 2100 1.0 1.0 2500 0 AK47
19 25 95 0.30 30 4 2500 1.0 1.0 3500 0 AUG
20 25 95 0.30 30 4 2400 1.0 1.0 3500 0 SG552
21 70 250 0.60 30 4 2200 0.9 2.0 4200 0 SG550
22 70 300 0.60 20 5 3200 0.9 2.0 5000 0 G3SG1
23 100 1400 0.60 10 4 2300 0.85 2.0 4750 0 AWP
24 20 95 0.55 100 2 4200 0.85 1.0 5750 0 M249
25 0 1000 0.0 1 1 0 1.5 0.0 200 3 FLASHBANG
26 50 1000 0.0 3 1 0 1.5 0.0 300 3 HE-GRENADE
27 0 1000 0.0 1 1 0 1.5 0.0 300 3 SMOKE-GRENADE
quad damage delay spread clip #ofclips reloaddelay walkingspeed bulletspeed money type name
Edited by FaT3oYCG

Interpreters have great power!Although they live in the shadow of compiled programming languages an interpreter can do anything that a compiled language can do, you just have to code it right.

Share this post


Link to post
Share on other sites



Hi!

Check out the _GUICtrlListView* udfs included in the standard autoit package. They provide lots different ways to work with the listview. For example if you want to get the current selection you can do:

_GUICtrlListView_GetSelectionMark

:)


Broken link? PM me and I'll send you the file!

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