Jump to content
MuffettsMan

_GUICtrlListView_GetItemText not working with variable

Recommended Posts

_GUICtrlListView_GetItemText seems to return data when I use a static indices but when i use it from a variable it spits back null....

 

sample code:

(when u select the second row - indice 1 it 'should' report back the value... however console log ends up:

$selectedRow ID: 1
 dynamic rowID: 
 static rowID: Row 1: Col 2
>Exit code: 0    Time: 12.189
 
static rowID is line 63 where i hardcoded 1 instead of using the variable from _GUICtrlListView_GetSelectedIndices
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>

Example()

Func Example()
    Global $hImage, $hListView

    ; Create GUI
    GUICreate("ListView Add SubItem", 400, 350)

    $selected = GUICtrlCreateButton("Selected", 276, 300, 73, 25)
    $hListView = GUICtrlCreateListView("", 2, 2, 394, 268, -1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
    GUISetState(@SW_SHOW)



    ; Add columns
    _GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)
    _GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 100)
    _GUICtrlListView_InsertColumn($hListView, 2, "Column 3", 100)

    ; Add items

      For $i = 0 To 50
         ; ConsoleWrite("i: " & $i & @CRLF)
          _GUICtrlListView_AddItem($hListView, "Row " & $i & ": Col 1", $i)
          _GUICtrlListView_AddSubItem($hListView, $i, "Row " & $i & ": Col 2", 1, 1)
          _GUICtrlListView_AddSubItem($hListView, $i, "Row " & $i & ": Col 3", 2, 2)
      Next
; ConsoleWrite("i: " & $i & @CRLF)
    ; Loop until the user exits.

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $selected
           getSelected()

        EndSwitch



   sleep(10) ; take it easy on the CPU.
WEnd

 EndFunc   ;==>Example




Func getSelected()
   $selectedRow = _GUICtrlListView_GetSelectedIndices($hListView) ; return the selected row
   ConsoleWrite("$selectedRow ID: " & $selectedRow & @CRLF)

   $rowID = _GUICtrlListView_GetItemText($hListView, $selectedRow, 1)
   ConsoleWrite(" dynamic rowID: " & $rowID & @CRLF)

   $rowID = _GUICtrlListView_GetItemText($hListView, 1, 1)
   ConsoleWrite(" static rowID: " & $rowID & @CRLF)
EndFunc ;==> getSelected

Don't let that status fool you, I am no advanced memeber!

Share this post


Link to post
Share on other sites

Actually if you change the line to this, it will work with the control ID or the variable.

$rowID = _GUICtrlListView_GetItemText($hListView, Number($selectedRow))

The function requires a number, _GUICtrlListView_GetSelectedIndices returns a string containing a number. I'm not sure why the SendMsg function works with the string, but the GUICtrlSendMsg function won't. Maybe it has something to do with the DLLCall function that converts the string to a number.


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

Share this post


Link to post
Share on other sites

thx BrewManNH - I didn't even try that because I always felt autoit was a loosely typed language (that converts a char to int on the fly or doesn't need to be specified) at least never had a problem with it in the past - least I know the workaround now 

ty ty again


Don't let that status fool you, I am no advanced memeber!

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

×
×
  • Create New...