Jump to content

GUICtrlRead returns a number from a listview instead of the text


PetterBomban
 Share

Recommended Posts

Hi folks.

I'm trying to automate blocking of students network access by bulk, instead of blocking each and every class manually.

So far so good, I have managed to make it work. Now I have to create a GUI for it, so that the other guys at the office can use it.

I'm having some trouble though. Instead of outputting the text in my listview, it outputs a number, no matter what I select.

Here are some screenshots to better explain:


R7xXqfq.pngDjdD2fp.png

#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <GUIListView.au3>
#include <WindowsConstants.au3>

mainGUI()

Func mainGUI()

    Local $msg

    Local $GUI = GUICreate("Menu", 1000, 850)
    
    Local $button1 = GUICtrlCreateButton("Button 1", 5, 30, 100, 25)
    
    Local $listOfGroups = GUICtrlCreateListView("", 5, 100, 180, 500, BitOR($LBS_STANDARD, $LBS_EXTENDEDSEL, $WS_VSCROLL, $LVS_SHOWSELALWAYS))
    Local $listOfGroupsItems = ["test", "testd", "asdasd", "asdasdasdasdasd"]

    For $groupItem in $listOfGroupsItems
        GUICtrlCreateListViewItem($groupItem, $listOfGroups)
    Next
    
    GUISetState()

    While 1
        
        $msg = GUIGetMsg()
        
        Select
            
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
                
            Case $msg = $button1
                $testRead = GUICtrlRead($listOfGroups)
                MsgBox(0, 'Button 1', $testRead)
    
        EndSelect
        
    WEnd
    
EndFunc ;==> mainGUI()

 

 

 

 

Link to comment
Share on other sites

  • Developers

These are the handles returned by the GUICtrlCreateListViewItem() statement which you aren't capturing.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

These are the handles returned by the GUICtrlCreateListViewItem() statement which you aren't capturing.

Jos

Could you give me an example of how it is done?

 

Edit: Found out how: 

GUICtrlRead(GUICtrlRead($listview)).

But now I am having another problem. How do I print out all the values selected? Currently, only one value at a time will show up.

Any pointers?

Edited by PetterBomban
Link to comment
Share on other sites

Use _GUICtrlListView_GetSelectedIndices  and loop through the array to find out what the text/information is from those selected indices.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I wouldn't use a For In loop with the array returned by the first function, the first element of the array is going to be the count of selected items in the listview. This is going to give you wrong results. You should use a regular For/Next loop instead and start the loop at 1 instead of zero.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I wouldn't use a For In loop with the array returned by the first function, the first element of the array is going to be the count of selected items in the listview. This is going to give you wrong results. You should use a regular For/Next loop instead and start the loop at 1 instead of zero.

Thanks a ton! It's as you said, the For..In loop made weird things happen.

$items = _GUICtrlListView_GetSelectedIndices($listOfGroups, True)
$itemsNum = UBound($items)

For $i = 1 To $itemsNum - 1
    $rowName = _GUICtrlListView_GetItemText($listOfGroups, Number($items[$i]), 0)
    ConsoleWrite("  -  ")
    ConsoleWrite($rowName)
Next
Edited by PetterBomban
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...