Jump to content

I want to make the information update when selected.


ERIC_DEUCHER
 Share

Go to solution Solved by Andreik,

Recommended Posts

I recently started using AutoIt, so go easy on me, haha. I created a GUI with some information on the screen, but I can't figure out how to make it so that when I select a ListViewItem, it updates the value in GUICtrlCreateInput.

my code:

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ListViewConstants.au3>


    Opt("TrayMenuMode", 1)
#Region ### START Koda GUI section ###
    $Form1 = GUICreate("Iniciar", 317, 608, 417, 120)
    
    local $bone_id, $aur_id

    $Write_screen_1 = GUICtrlCreateLabel("CAC ID", 16, 64, 105, 20)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")

    $Write_screen_2 = GUICtrlCreateLabel("Aura ID", 40, 288, 48, 20)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")

    $Start_Convert = GUICtrlCreateButton("Start_Convert", 16, 432, 283, 105)

    $Dire_Tel = GUICtrlCreateLabel("...", 8, 552, 305, 52)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    
    
    $RE_cac_ID = GUICtrlCreateInput("", 16, 88, 105, 24)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")

    $RE_aura_ID = GUICtrlCreateInput("", 16, 312, 105, 24)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")

    ;ListView
    GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 40)
    GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 100)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    GUICtrlSetResizing(-1, $GUI_DOCKRIGHT)
    $ListView1_Bon = GUICtrlCreateListView("ID|Name", 144, 8, 154, 193)
    $ListView1_CAC_1 = GUICtrlCreateListViewItem("64|Human Male", $ListView1_Bon)
    $ListView1_CAC_2 = GUICtrlCreateListViewItem("65|Human Female", $ListView1_Bon)
    $ListView1_CAC_3 = GUICtrlCreateListViewItem("66|Saiyan Male", $ListView1_Bon)
    $ListView1_CAC_4 = GUICtrlCreateListViewItem("67|Saiyan Female", $ListView1_Bon)
    $ListView1_CAC_5 = GUICtrlCreateListViewItem("68|Namekian", $ListView1_Bon)
    $ListView1_CAC_6 = GUICtrlCreateListViewItem("69|Frieza Race", $ListView1_Bon)
    $ListView1_CAC_7 = GUICtrlCreateListViewItem("6a|Majin Male", $ListView1_Bon)
    $ListView1_CAC_8 = GUICtrlCreateListViewItem("6b|Majin Female", $ListView1_Bon)

    GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 40)
    GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 60)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    $ListView2_Auras = GUICtrlCreateListView("ID|Name", 144, 208, 154, 214)
    $ListView2_aura_1 = GUICtrlCreateListViewItem("0|Blue", $ListView2_Auras)
    $ListView2_aura_2 = GUICtrlCreateListViewItem("1|Violet", $ListView2_Auras)
    $ListView2_aura_3 = GUICtrlCreateListViewItem("2|Purple", $ListView2_Auras)
    $ListView2_aura_4 = GUICtrlCreateListViewItem("3|Pink", $ListView2_Auras)
    $ListView2_aura_5 = GUICtrlCreateListViewItem("4|Red", $ListView2_Auras)
    $ListView2_aura_6 = GUICtrlCreateListViewItem("5|Yellow", $ListView2_Auras)
    $ListView2_aura_7 = GUICtrlCreateListViewItem("A|Green", $ListView2_Auras)
    $ListView2_aura_8 = GUICtrlCreateListViewItem("F|white", $ListView2_Auras)
    $ListView2_aura_9 = GUICtrlCreateListViewItem("C|Empty", $ListView2_Auras)
    ;ListView


    GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $ListView1_CAC_1
            $bone_id = 777
            
            Case $Start_Convert
            Exit

        EndSwitch
    WEnd

 

Edited by Melba23
Added code tags
Link to comment
Share on other sites

  • Solution

This can be a way to do it:

;~  #include <FileConstants.au3>
;~ #include <MsgBoxConstants.au3>
;~ #include <ButtonConstants.au3>
;~ #include <EditConstants.au3>
#include <GUIConstantsEx.au3>
;~ #include <GUIListBox.au3>
;~ #include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ListViewConstants.au3>
#include <StructureConstants.au3>
#include <GuiListView.au3>

Opt("TrayMenuMode", 1)
#Region ### START Koda GUI section ###
$Form1 = GUICreate("Iniciar", 317, 608, 417, 120)

local $bone_id, $aur_id

$Write_screen_1 = GUICtrlCreateLabel("CAC ID", 16, 64, 105, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")

$Write_screen_2 = GUICtrlCreateLabel("Aura ID", 40, 288, 48, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")

$Start_Convert = GUICtrlCreateButton("Start_Convert", 16, 432, 283, 105)

$Dire_Tel = GUICtrlCreateLabel("...", 8, 552, 305, 52)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")


Global $RE_cac_ID = GUICtrlCreateInput("", 16, 88, 105, 24)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")

Global $RE_aura_ID = GUICtrlCreateInput("", 16, 312, 105, 24)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")

;ListView
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 40)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 100)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetResizing(-1, $GUI_DOCKRIGHT)
$ListView1_Bon = GUICtrlCreateListView("ID|Name", 144, 8, 154, 193)
$ListView1_CAC_1 = GUICtrlCreateListViewItem("64|Human Male", $ListView1_Bon)
$ListView1_CAC_2 = GUICtrlCreateListViewItem("65|Human Female", $ListView1_Bon)
$ListView1_CAC_3 = GUICtrlCreateListViewItem("66|Saiyan Male", $ListView1_Bon)
$ListView1_CAC_4 = GUICtrlCreateListViewItem("67|Saiyan Female", $ListView1_Bon)
$ListView1_CAC_5 = GUICtrlCreateListViewItem("68|Namekian", $ListView1_Bon)
$ListView1_CAC_6 = GUICtrlCreateListViewItem("69|Frieza Race", $ListView1_Bon)
$ListView1_CAC_7 = GUICtrlCreateListViewItem("6a|Majin Male", $ListView1_Bon)
$ListView1_CAC_8 = GUICtrlCreateListViewItem("6b|Majin Female", $ListView1_Bon)
Global $hListview_Bon = GUICtrlGetHandle($ListView1_Bon)

GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 40)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 60)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$ListView2_Auras = GUICtrlCreateListView("ID|Name", 144, 208, 154, 214)
$ListView2_aura_1 = GUICtrlCreateListViewItem("0|Blue", $ListView2_Auras)
$ListView2_aura_2 = GUICtrlCreateListViewItem("1|Violet", $ListView2_Auras)
$ListView2_aura_3 = GUICtrlCreateListViewItem("2|Purple", $ListView2_Auras)
$ListView2_aura_4 = GUICtrlCreateListViewItem("3|Pink", $ListView2_Auras)
$ListView2_aura_5 = GUICtrlCreateListViewItem("4|Red", $ListView2_Auras)
$ListView2_aura_6 = GUICtrlCreateListViewItem("5|Yellow", $ListView2_Auras)
$ListView2_aura_7 = GUICtrlCreateListViewItem("A|Green", $ListView2_Auras)
$ListView2_aura_8 = GUICtrlCreateListViewItem("F|white", $ListView2_Auras)
$ListView2_aura_9 = GUICtrlCreateListViewItem("C|Empty", $ListView2_Auras)
Global $hListview_Auras = GUICtrlGetHandle($ListView2_Auras)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')


While True
    Switch GUIGetMsg()
        Case $ListView1_CAC_1
            $bone_id = 777
        Case $GUI_EVENT_CLOSE, $Start_Convert
            Exit
    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    Local $hWndFrom = HWnd($tNMHDR.hWndFrom)
    Local $tNMITEMACTIVATE
    Switch $tNMHDR.Code
        Case $NM_CLICK
            Switch $hWndFrom
                Case $hListview_Bon
                    $tNMITEMACTIVATE = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    GUICtrlSetData($RE_cac_ID, _GUICtrlListView_GetItemText($hWndFrom, $tNMITEMACTIVATE.Index))
                Case $hListview_Auras
                    $tNMITEMACTIVATE = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    GUICtrlSetData($RE_aura_ID, _GUICtrlListView_GetItemText($hWndFrom, $tNMITEMACTIVATE.Index))
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

By the way, I don't think you fully understand how -1 works as parameter for control IDs so it would be better to use real control IDs for now. For example you have this portion of code:

$Dire_Tel = GUICtrlCreateLabel("...", 8, 552, 305, 52)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")


Global $RE_cac_ID = GUICtrlCreateInput("", 16, 88, 105, 24)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")

Global $RE_aura_ID = GUICtrlCreateInput("", 16, 312, 105, 24)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")

;ListView
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 40)          ; <<< ----- what do you think it happens here?
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 100)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetResizing(-1, $GUI_DOCKRIGHT)
$ListView1_Bon = GUICtrlCreateListView("ID|Name", 144, 8, 154, 193)

 

Edited by Andreik

When the words fail... music speaks.

Link to comment
Share on other sites

  • Moderators

ERIC_DEUCHER,

Welcome to the AutoIt forums.

When you post code in future please use Code tags - see here how to do it.  Then you get a scrolling box and syntax colouring as you can see above now I have added the tags. Thanks in advance for your cooperation.

And looking at the code it seems that you might not yet have read the Forum rules. Please read them now - particularly the bit about not discussing game automation. As this question is purely a data handling matter I have decided to let it run, but I suggest you think carefuly before asking more questions about game-related code.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

You can achieve the same result with native functions as well:

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

Opt("TrayMenuMode", 1)
#Region ### START Koda GUI section ###
$Form1 = GUICreate("Iniciar", 317, 608, 417, 120)

Global $bone_id, $aur_id, $RE_cac_ID, $RE_aura_ID, $hListview_Bon, $hListview_Auras

$Write_screen_1 = GUICtrlCreateLabel("CAC ID", 16, 64, 105, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")

$Write_screen_2 = GUICtrlCreateLabel("Aura ID", 40, 288, 48, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")

$Start_Convert = GUICtrlCreateButton("Start_Convert", 16, 432, 283, 105)

$Dire_Tel = GUICtrlCreateLabel("...", 8, 552, 305, 52)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")


$RE_cac_ID = GUICtrlCreateInput("", 16, 88, 105, 24)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")

$RE_aura_ID = GUICtrlCreateInput("", 16, 312, 105, 24)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")

;ListView
$ListView1_Bon = GUICtrlCreateListView("ID|Name", 144, 8, 154, 193)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 40)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 100)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetResizing(-1, $GUI_DOCKRIGHT)
$ListView1_CAC_1 = GUICtrlCreateListViewItem("64|Human Male", $ListView1_Bon)
$ListView1_CAC_2 = GUICtrlCreateListViewItem("65|Human Female", $ListView1_Bon)
$ListView1_CAC_3 = GUICtrlCreateListViewItem("66|Saiyan Male", $ListView1_Bon)
$ListView1_CAC_4 = GUICtrlCreateListViewItem("67|Saiyan Female", $ListView1_Bon)
$ListView1_CAC_5 = GUICtrlCreateListViewItem("68|Namekian", $ListView1_Bon)
$ListView1_CAC_6 = GUICtrlCreateListViewItem("69|Frieza Race", $ListView1_Bon)
$ListView1_CAC_7 = GUICtrlCreateListViewItem("6a|Majin Male", $ListView1_Bon)
$ListView1_CAC_8 = GUICtrlCreateListViewItem("6b|Majin Female", $ListView1_Bon)
$hListview_Bon = GUICtrlGetHandle($ListView1_Bon)

$ListView2_Auras = GUICtrlCreateListView("ID|Name", 144, 208, 154, 214)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 40)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 60)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$ListView2_aura_1 = GUICtrlCreateListViewItem("0|Blue", $ListView2_Auras)
$ListView2_aura_2 = GUICtrlCreateListViewItem("1|Violet", $ListView2_Auras)
$ListView2_aura_3 = GUICtrlCreateListViewItem("2|Purple", $ListView2_Auras)
$ListView2_aura_4 = GUICtrlCreateListViewItem("3|Pink", $ListView2_Auras)
$ListView2_aura_5 = GUICtrlCreateListViewItem("4|Red", $ListView2_Auras)
$ListView2_aura_6 = GUICtrlCreateListViewItem("5|Yellow", $ListView2_Auras)
$ListView2_aura_7 = GUICtrlCreateListViewItem("A|Green", $ListView2_Auras)
$ListView2_aura_8 = GUICtrlCreateListViewItem("F|white", $ListView2_Auras)
$ListView2_aura_9 = GUICtrlCreateListViewItem("C|Empty", $ListView2_Auras)
$hListview_Auras = GUICtrlGetHandle($ListView2_Auras)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')


While True
    Switch GUIGetMsg()
        Case $ListView1_CAC_1
            $bone_id = 777
        Case $GUI_EVENT_CLOSE, $Start_Convert
            Exit
    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    Local $hWndFrom = HWnd($tNMHDR.hWndFrom)
    Local $aData
    Switch $tNMHDR.Code
        Case $NM_CLICK
            Switch $hWndFrom
                Case $hListview_Bon
                    $aData = StringSplit(GUICtrlRead(GUICtrlRead($ListView1_Bon)), '|')
                    If IsArray($aData) Then GUICtrlSetData($RE_cac_ID, $aData[0] > 1 ? $aData[1] : '')
                Case $hListview_Auras
                    $aData = StringSplit(GUICtrlRead(GUICtrlRead($ListView2_Auras)), '|')
                    If IsArray($aData) Then GUICtrlSetData($RE_aura_ID, $aData[0] > 1 ? $aData[1] : '')
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

 

Edited by Andreik

When the words fail... music speaks.

Link to comment
Share on other sites

If you pass -1 it is like you would pass the ID of the last created control. In the example above it doesn't make any sense.

$RE_aura_ID = GUICtrlCreateInput("", 16, 312, 105, 24)  ; <<< --- this is the last created control
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")

;ListView
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 40)   ; <<< --- LVM_SETCOLUMNWIDTH is sent to $RE_aura_ID which doesn't make any sense

In my opinion it's better to pass the exact control ID so there is no confusion and to avoid possible issues if another control it's created meanwhile.

When the words fail... music speaks.

Link to comment
Share on other sites

16 minutes ago, ERIC_DEUCHER said:

The correct approach is to simply remove the -1 from the code, then?

Both are correct but using -1 is not as using a specific control ID. In case you later add code to your script, using the last created control ID (-1) might lead to undesired behavior.

As you can see in the second example posted (using native functions), if you intend to set these properties to the list view, logically would be to place these just after the creation of the list view.

$ListView2_Auras = GUICtrlCreateListView("ID|Name", 144, 208, 154, 214) ; <<< --- this is the last created control
; If a new control is created here, the message and the font are assigned to this new control
; but since there is no control created here the following code is equivalent
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 40)      ; <<< --- this is equivalent of GUICtrlSendMsg($ListView2_Auras, $LVM_SETCOLUMNWIDTH, 0, 40)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 60)      ; <<< --- this is equivalent of GUICtrlSendMsg($ListView2_Auras, $LVM_SETCOLUMNWIDTH, 1, 60)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")     ; <<< --- this is equivalent of GUICtrlSetFont(ListView2_Auras, 10, 400, 0, "MS Sans Serif")

The safer way it's to set the intended control ID like below:

$ListView2_Auras = GUICtrlCreateListView("ID|Name", 144, 208, 154, 214)
...
; If here is some more code, even if a new control is created
; the messages below and the font will apply to $ListView2_Auras
...
GUICtrlSendMsg($ListView2_Auras, $LVM_SETCOLUMNWIDTH, 0, 40)
GUICtrlSendMsg($ListView2_Auras, $LVM_SETCOLUMNWIDTH, 1, 60)
GUICtrlSetFont($ListView2_Auras, 10, 400, 0, "MS Sans Serif")

 

Edited by Andreik

When the words fail... music speaks.

Link to comment
Share on other sites

Of course you can do something like this but it's not as good as the code above:

#include <ListViewConstants.au3>
#include <GUIConstants.au3>

Global $cLastSelection = Null, $cCurrentSelection, $aRead

$hMain = GUICreate('Example', 400, 400)
$cListview = GUICtrlCreateListView('ID|Name', 10, 10, 380, 300)
$cInput = GUICtrlCreateInput('', 10, 350, 150, 30)
GUICtrlCreateListViewItem("64|Human Male", $cListview)
GUICtrlCreateListViewItem("65|Human Female", $cListview)
GUICtrlCreateListViewItem("66|Saiyan Male", $cListview)
GUICtrlCreateListViewItem("67|Saiyan Female", $cListview)
GUICtrlCreateListViewItem("68|Namekian", $cListview)
GUICtrlCreateListViewItem("69|Frieza Race", $cListview)
GUICtrlCreateListViewItem("6a|Majin Male", $cListview)
GUICtrlCreateListViewItem("6b|Majin Female", $cListview)
GUICtrlSendMsg($cListview, $LVM_SETCOLUMNWIDTH, 0, 40)
GUICtrlSendMsg($cListview, $LVM_SETCOLUMNWIDTH, 1, 100)
GUISetState(@SW_SHOW, $hMain)

While True
    If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
    $cCurrentSelection = GUICtrlRead($cListview)
    If $cCurrentSelection <> $cLastSelection Then
        $cLastSelection = $cCurrentSelection
        $aRead = StringSplit(GUICtrlRead($cCurrentSelection), '|')
        If IsArray($aRead) Then GUICtrlSetData($cInput, $aRead[0] > 1 ? $aRead[1] : '')
    EndIf
WEnd

When the words fail... music speaks.

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...