Jump to content

Read value from ListView on mouse click


Go to solution Solved by PlayHD,

Recommended Posts

#include <GuiConstantsEx.au3>
#include <File.au3>
#include <Array.au3>
#include <ListviewConstants.au3>
#include <GuiListView.au3>

GUICreate("Automation", 300, 500)
$mylist = GUICtrlCreateList("", 10, 60, 280, 100)
$add = GUICtrlCreateButton("Add", 10, 35, 75, 20)

GUISetState(@SW_SHOW)

    

While 1
       $msg = GUIGetMsg()
    Switch $msg
 Case $add
    Local $FileList
    _FileReadToArray("C:\Users\Danny Tan\Desktop\test.txt", $FileList)
            For $i = 1 To $FileList[0]
                GUICtrlSetData($mylist, $FileList[$i])
            Next
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Need some helps here,

How do i trying to read the data when i select it from the listview. i couldn't get it worked.

Link to comment
Share on other sites

  • Solution

Something like this ?

#include <GuiConstantsEx.au3>
#include <File.au3>
#include <Array.au3>
#include <ListviewConstants.au3>
#include <GuiListView.au3>
Local $FileList ;declare variables here, not in a loop
Local $DataReadFromList

$GUI = GUICreate("Automation", 300, 500) ;is good to save the window handle
$mylist = GUICtrlCreateList("", 10, 60, 280, 100)
$add = GUICtrlCreateButton("Add", 10, 35, 75, 20)

GUISetState(@SW_SHOW,$GUI) ;;;;

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $add
            _FileReadToArray("C:\Users\Danny Tan\Desktop\test.txt", $FileList)
            If @error Then ContinueLoop ;if file not found do something (else the program will generate error)
            For $i = 1 To $FileList[0]
                GUICtrlSetData($mylist, $FileList[$i])
            Next
        Case $mylist ;if select a item from list do stuff
            $DataReadFromList = GUICtrlRead($mylist)
            MsgBox(0,0,$DataReadFromList)
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd
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...