Jump to content
Sign in to follow this  

guictrlread dont read listview

Recommended Posts

hi  guy i  have program ,  in this prog  i  want  by  a  button open  alittle  listview   with 2 column   select  one  of  item  and  put  in   input  (in principal form )

this is a code

Func _anagrafica_tab2()

    $Form2 = GUICreate("Cerca in Anagrafica", 346, 267, 477, 179)
    $Input0 = GUICtrlCreateInput("", 16, 40, 185, 21)
    $List4 = GUICtrlCreateListView("Nome | ID   ", 5, 74, 332, 149,$LVS_EX_GRIDLINES)
    _GUICtrlListView_SetExtendedListViewStyle($List4, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_SUBITEMIMAGES)) ; questa stringa fa la griglia stile excel
    GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 280) ; Nome Anagrafica
    GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 45) ; ID Nome
    $Label1 = GUICtrlCreateLabel("Cerca", 16, 23, 32, 17)
    $Button1 = GUICtrlCreateButton("Cerca", 216, 40, 75, 21, 0)
    $Button2 = GUICtrlCreateButton("Inserisci", 256, 232, 75, 25, 0)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_chiudi")

Local $aRow, $iRows, $iCols
    _SQLite_GetTable2d($Db, "SELECT * FROM anagrafica;", $aRow, $iRows, $iCols)
        For $i = 1 To $iRows - 0
        _GUICtrlListView_AddItem($List4, $arow[$i][1], $i) ;nome ditta
        _GUICtrlListView_AddSubItem($List4,$l, $arow[$i][0], 1, 1) ; mail




    GUICtrlSetOnEvent($Button1, "_cercaanagrafica_tab2")
    GUICtrlSetOnEvent($Button2, "On_Button3")
EndFunc   ;==>_anagrafica_tab2

Func On_Button3(); bootone  inserisci anagrafica
    Local $test=GUICtrlRead($List4,1)

    $sSelected_Data = StringTrimRight(GUICtrlRead(GUICtrlRead($List4)), 1)
    $string = StringSplit($sSelected_Data, "|") ;Crea un array con le lettere, ogni volta che c' è \ creo un dato
    $verifica = $string[1]
    If $sSelected_Data <> "" Then

        GUICtrlSetData($Input1_tab2, $verifica)

EndFunc   ;==>On_Button3

Func _cercaanagrafica_tab2()
    $testodacercare = GUICtrlRead($Input0)
    $iI = _GUICtrlListView_FindInText($List4, $testodacercare)
    MsgBox(4160, "Info", "Target: " & $iI)
    _GUICtrlListView_EnsureVisible($List4, $iI)
    ;_GUICtrlListView_SetItemDropHilited($List4, $iI,True)
    _GUICtrlListView_SetItemFocused($List4, $iI,True)
EndFunc   ;==>_cercaanagrafica_tab2

when i try to read $list4  not read  give me  always  0   :(

Local $test=GUICtrlRead($List4,1)

Share this post

Link to post
Share on other sites


As the Help file explains, you need to use GUICtrlRead twice to get the text from a ListView - first to get the ControlID of the selected item and then again to get the content.  You actually do this a few lines later in your script:

$sSelected_Data = StringTrimRight(GUICtrlRead(GUICtrlRead($List4)), 1)

So you need to do the same thing if you want to check the value beforehand.  :)

Furthermore, why are you using the "advanced" flag when trying to display the content?  All that does for ListViewItems is to return "The state of the ListViewItem if $LVS_EX_CHECKBOXES exStyle used" as also explained in the Help file.  Well worth reading it carefully when things do not seem to work as expected. ;)


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:


ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area


Share this post

Link to post
Share on other sites

How come you are using Local $test = GUICtrlRead($List4, 1) in one line but using $sSelected_Data = StringTrimRight(GUICtrlRead(GUICtrlRead($List4)), 1) in another line? Either you're using code you don't understand or you made a mistake somewhere. Because the second line will read the text of the ListView item, and the first one will read the index of it.

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

This maybe relates to your issue as well. The On_Button3 function does not know what the variable $List4 is. You probably need to either declare it globally or pass it's value to the called function.

Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post

Link to post
Share on other sites

Show us more code, so we can run it and see what is really going on.

Alternatively, try the sugestion in the 2nd post.


Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples


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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...