Sign in to follow this  
Followers 0
cgasb

Selecting items from a list

3 posts in this topic

I create an array with PC names and then populate a listview. I am currently getting the selected PC by using $GUI_EVENT_PRIMARYDOWN and GUICtrlRead in the corrosponding function, but that's not accurate as the function is activated by clicking anywhere in the GUI.

;=============================================
; Define some GUI stuff and display the GUI
;=============================================
GUICreate("Computer List", 200, 250) ; will create a dialog box that when displayed is centered
$PCView = GUICtrlCreateList (" ",17,17,120,200)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "Value")
GUISetState ()

;=============================================
; Setup the list with computer names
;=============================================
For $z = 1 To $aPC[0]
    GUICtrlSetData(-1,$aPC[$z])
Next

;=============================================
; Idle around
;=============================================
While 1
    Sleep(1000)
Wend

;=============================================
; Read the computer name that is selected and do something
;=============================================
Func Value()
    $valuex = GUICtrlRead($PCView)
    MsgBox(0, "", $valuex)
EndFunc

;=============================================
; Close the GUI and exit the program
;=============================================
Func CLOSEClicked()
  Exit
EndFunc

What would be the "proper" way to grab what is clicked in the list?

Share this post


Link to post
Share on other sites



#include<GuiListBox.au3>
#include<GUIConstantsEx.au3>
Opt("GuiOnEventMode", 1)
;=============================================
; Define some GUI stuff and display the GUI
;=============================================
GUICreate("Computer List", 200, 250); will create a dialog box that when displayed is centered
$PCView = GUICtrlCreateList (" ",17,17,120,200)
    GuiCtrlSetOnEvent(-1, '_Test')

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

GUISetState ()

;=============================================
; Setup the list with computer names
;=============================================
Local $aPc[5] = [4, 7, 8, 9, 11]
For $z = 1 To $aPC[0]
    GUICtrlSetData(-1,$aPC[$z])
Next

;=============================================
; Idle around
;=============================================
While 1
    Sleep(1000)
Wend

Func _Test()
    Msgbox(0, 'Currently selected...', 'Index = ' & _GuictrlListBox_GetCurSel($PCView) & @CRLF & 'Value = ' & _GuiCtrlLIstBox_GetText($PCView, _GuictrlListBox_GetCurSel($PCView)))
EndFunc


;=============================================
; Close the GUI and exit the program
;=============================================
Func CLOSEClicked()
  Exit
EndFunc


My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites

#include<GuiListBox.au3>
#include<GUIConstantsEx.au3>
Opt("GuiOnEventMode", 1)
;=============================================
; Define some GUI stuff and display the GUI
;=============================================
GUICreate("Computer List", 200, 250); will create a dialog box that when displayed is centered
$PCView = GUICtrlCreateList (" ",17,17,120,200)
    GuiCtrlSetOnEvent(-1, '_Test')

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

GUISetState ()

;=============================================
; Setup the list with computer names
;=============================================
Local $aPc[5] = [4, 7, 8, 9, 11]
For $z = 1 To $aPC[0]
    GUICtrlSetData(-1,$aPC[$z])
Next

;=============================================
; Idle around
;=============================================
While 1
    Sleep(1000)
Wend

Func _Test()
    Msgbox(0, 'Currently selected...', 'Index = ' & _GuictrlListBox_GetCurSel($PCView) & @CRLF & 'Value = ' & _GuiCtrlLIstBox_GetText($PCView, _GuictrlListBox_GetCurSel($PCView)))
EndFunc


;=============================================
; Close the GUI and exit the program
;=============================================
Func CLOSEClicked()
  Exit
EndFunc
That worked beautifully when I incorporated your adjustments. Thanks for the lesson.

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