Jump to content

_GUICtrlListView_GetItemTextString question ?


larksp
 Share

Recommended Posts

I was wondering why  i have to add    "+1 -1 "   ConsoleWrite (_GUICtrlListView_GetItemTextString($idListview,$no +1 -1) & @CRLF & $no & @CRLF )   to make it work why it cant just take
as you can see the $no is a Number  ConsoleWrite (_GUICtrlListView_GetItemTextString($idListview,$no) & @CRLF & $no & @CRLF ) does not work

code copied from a post by  ("InunoTaishou")
i was just playing around learning try to learn how to right click on the list view and copy the information to clipboard or to save to a file the selected test


NEXT practice will be How to do multi selected lines or say tick boxes and the ones with the ticks in get copied

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.2
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here


#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3>
#include <GuiListView.au3>
Global $no
Global Const $VALUE_DEPARTMENT = 0
Global Const $VALUE_EMAIL = 1
Global Const $VALUE_NAME = 2
Global Const $VALUE_PHONE = 3

Global $title = "E-Mail address lookup"
Global $result[][4] = [["Dept1", "User1@mail.com", "User1", "555-555-5555"], ["Dept2", "User2@mail.com", "User2", "555-555-5555"], ["Dept3", "User3@mail.com", "User3", "555-555-5555"]]


Global $ControlID = GUICreate($title, 550, 160)
Global $idListview = GUICtrlCreateListView("Deparment|E-Mail Address|Name|Telephone Number", 10, 10, 530, 150)
;~ Global $get_email

Global $rset = UBound($result) - 1
For $count = 0 To $rset
    GUICtrlCreateListViewItem($result[$count][0] & "|" & $result[$count][1] & "|" & $result[$count][2] & "|" & $result[$count][3], $idListview)
Next

Global $context = GUICtrlCreateContextMenu($idListview)
Global $menuitem = GUICtrlCreateMenuItem("Copy email address", $context)
;~ Global $copytext
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case -3
            Exit
        Case $menuitem
            $no = _GUICtrlListView_GetSelectedIndices($idListview)
            _ShowText(_GUICtrlListView_GetSelectedIndices($idListview))
            ConsoleWrite (_GUICtrlListView_GetItemTextString($idListview,$no +1 -1) & @CRLF & $no & @CRLF )
            ConsoleWrite (_GUICtrlListView_GetItemTextString($idListview,$no) & @CRLF & $no & @CRLF )
    EndSwitch
WEnd

Func _ShowText($vSelected)
    Local $sEmails = ""
    Local $sNames = ""
    If (IsArray($vSelected)) Then
;~         ; In case multiple items are selected
        For $i = 0 to UBound($vSelected) -1
            $sNames &= $result[$vSelected][$VALUE_NAME] & ", "
            $sEmails &= $result[$vSelected][$VALUE_EMAIL] & ", "

        Next
        $sEmails = StringTrimRight($sEmails, 2)
        $sNames = StringTrimRight($sNames, 2)

        ConsoleWrite($sNames & " put in clipboard" & @CRLF)
        ClipPut($sEmails)
    Else
;~      msgbox (0,0,0)
        ConsoleWrite($result[$vSelected][$VALUE_NAME] & " put in clipboard" & @CRLF)
        ClipPut($result[$vSelected][$VALUE_EMAIL])
    EndIf
EndFunc   ;==>_ShowText

 

Link to comment
Share on other sites

_GUICtrlListView_GetSelectedIndices returns a string, even though the string is a number. The function _GUICtrlListView_GetItemTextString requires a number for the index you want to read from. If you change the line below you will see that it works correctly.

;~          $no = _GUICtrlListView_GetSelectedIndices($idListview) <<<<<<<<<<<<<< Original line
            $no = Number(_GUICtrlListView_GetSelectedIndices($idListview)) ; Modified line

When you added and subtracted from that string, AutoIt converted the string to a number for you, there's no conversion done with the Windows API that's being used so you have to give it what it's expecting, in this case 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

Link to comment
Share on other sites

:thumbsup:

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

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