Valnurat

Get Listview content issue

7 posts in this topic

I don't understand why I can't get the picked content from a Listview.

The content in my listview has been added with an array.

When I press the $idNewEntry I just get a message with 0 as returned.

Do I do something wrong?

 

Global $idListview, $idOKay, $hMainForm, $idNewEntry, $idEditEntry, $aMsg, $hNewEntry, $idNewOKay, $idNewCancel


_MainFormCreate()
_Main()


Func _MainFormCreate()
    ; Create GUI
    $hMainForm = GUICreate("Computer Asset", 1027, 400)
    $idListview = GUICtrlCreateListView("", 2, 2, 1024, 268);,Default, BitOR($LVS_SHOWSELALWAYS, $LVS_EX_GRIDLINES,$LVS_EX_FULLROWSELECT))

    ; Add columns
    _GUICtrlListView_AddColumn($idListview, "Computername", 100,2)
    _GUICtrlListView_AddColumn($idListview, "Tkt No.", 100,2)
    _GUICtrlListView_AddColumn($idListview, "Req No.", 100,2)
    _GUICtrlListView_AddColumn($idListview, "Order Date", 100,2)
    _GUICtrlListView_AddColumn($idListview, "Costcenter", 100,2)
    _GUICtrlListView_AddColumn($idListview, "Username", 100,2)
    _GUICtrlListView_AddColumn($idListview, "Model", 100,2)
    _GUICtrlListView_AddColumn($idListview, "Current Location", 100,2)
    _GUICtrlListView_AddColumn($idListview, "Option", 100,2)
    _GUICtrlListView_AddColumn($idListview, "Shipdate", 100,2)
    $idNewEntry = GUICtrlCreateButton("New", 310, 290, 85, 25)
    $idEditEntry = GUICtrlCreateButton("New", 310, 290, 85, 25)
    GUISetState()
EndFunc

Func _NewFormCreate()
    $hNewEntry = GUICreate("Create New", 500, 500, -1, -1,-1,-1,$hMainForm)
    $idNewOKay = GUICtrlCreateButton("Ok", 110, 290, 85, 25)
    $idNewCancel = GUICtrlCreateButton("Cancel", 310, 290, 85, 25)
    GUISetState()
EndFunc

Func _Main()
    Local $sConnectionString = 'DRIVER={' & $sDriver & '};SERVER=' & $sServer & ';DATABASE=' & $sDatabase & ';UID=' & $sUser & ';PWD=' & $sPassword & ';'
    Local $oConnection = _ADO_Connection_Create()
    _ADO_Connection_OpenConString($oConnection, $sConnectionString)
    If @error Then Return SetError(@error, @extended, $ADO_RET_FAILURE)
    Local $sTableName = 'StaffMemberUser.ComputerAsset'
    Local $sQUERY = "Select Computername, TktNo, ReqNo, OrderDate, CostCenter, Username, Model, CurrentLocation, Note, Shipdate from " & $sTableName
    Local $oRecordset = _ADO_Execute($oConnection, $sQUERY)
    Local $aRecordsetArray = _ADO_Recordset_ToArray($oRecordset, False)
    Local $aRecordset_inner = _ADO_RecordsetArray_GetContent($aRecordsetArray)

    _GUICtrlListView_SetItemCount($idListview, UBound($aRecordset_inner) - 1)

    _GUICtrlListView_AddArray($idListview, $aRecordset_inner)

    ; CleanUp
    $oRecordset = Null
    _ADO_Connection_Close($oConnection)
    $oConnection = Null
    ; Loop until the user exits.
    While 1
        $aMsg = GUIGetMsg(1)
        Switch $aMsg[1]
            Case $hMainForm
                Switch $aMsg[0]
                    Case $GUI_EVENT_CLOSE
                        ExitLoop
                    Case $idNewEntry
                        MsgBox($MB_SYSTEMMODAL, "listview item", GUICtrlRead(GUICtrlRead($idListview)), 2)
                        _NewFormCreate()
                        GUISetState(@SW_DISABLE,$hMainForm)
                    Case $idListview
                        MsgBox($MB_SYSTEMMODAL, "listview", "clicked=" & GUICtrlGetState($idListview), 2)
                EndSwitch
            Case $hNewEntry
                Switch $aMsg[0]
                    Case $GUI_EVENT_CLOSE
                        GUIDelete($hNewEntry)
                        GUISetState(@SW_ENABLE, $hMainForm)
                EndSwitch
        EndSwitch
    WEnd
    GUIDelete()
EndFunc

 


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites



The issue seems to be the use of _GUICtrlListView_AddArray.
Using GUICtrlCreateListViewItem for each item, I have no problem reading the selected text.

One way to get the text while using  _AddArray is to use the UDF functions:

MsgBox($MB_SYSTEMMODAL, "listview item", _GUICtrlListView_GetItemText($idListview, int(_GUICtrlListView_GetSelectedIndices($idListview))), 2)

 

Share this post


Link to post
Share on other sites

If you use the UDF functions on listviews, then you need to use the listview UDF to work with the listview. You should probably be using _GUICtrlListView_GetItemText.


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

#4 ·  Posted

15 hours ago, kurtykurtyboy said:

The issue seems to be the use of _GUICtrlListView_AddArray.
Using GUICtrlCreateListViewItem for each item, I have no problem reading the selected text.

One way to get the text while using  _AddArray is to use the UDF functions:

MsgBox($MB_SYSTEMMODAL, "listview item", _GUICtrlListView_GetItemText($idListview, int(_GUICtrlListView_GetSelectedIndices($idListview))), 2)

 

Thank you, but why do I only retrieve the 1st column?

I need to get all columns in the listview.


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

#5 ·  Posted

If I do this:

Local $iIndex = _GUICtrlListView_GetSelectedIndices($idListview)
MsgBox($MB_SYSTEMMODAL, "listview item", $iIndex, 2)

I can clearly see the index I selected. So  _GUICtrlListView_GetSelectedIndices($idListview), gives me the index of the selected.

but if I do this, it does not work:

_GUICtrlListView_GetItemTextArray($idListview, _GUICtrlListView_GetSelectedIndices($idListview))

But this does:

_GUICtrlListView_GetItemTextArray($idListview, int(_GUICtrlListView_GetSelectedIndices($idListview)))


Why do I need to use the INT?


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

#6 ·  Posted

_GuiCtrlListView_GetSelectedIndices returns a string  or an array, depending on the second parameter. _GUICtrlListView_GetItemTextArray requires a number for the index, using int converts the returned string to a number.

Share this post


Link to post
Share on other sites

#7 ·  Posted

Ahhh, yes. Thank you. :)


Yours sincerely

Kenneth.

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

  • Similar Content

    • X_xkijux_x
      By X_xkijux_x
      Ok so im using this program. clarify for school. I would like to have a program that takes every word i type in microsoft word and searches on it in claryfi. is this possible. I would like to have the program not stopping me from typing more after that word. Like when i type a word it auto search it on clarify without making me stop typing and if i want to change i can do that and if im fine that word i can just keep typing and it will search after the next word. 
    • Miliardsto
      By Miliardsto
      Is this possible to make program works like in diagram? There is so much encryption methods and UDFs are they give security? If the $Address will be crypted with some encryption algorithm could be possible to get the value of $Address in easy way? Of course We know its easy too look into autoit code and get value of variable and so We dont want to anyone see $Address value - there are functions Could func1.au3, func2.au3.. be for example func1.php or other type of file? As we know .php files are unnable to see. For example func1 would be read by FileRead() and then Execute() Is this generally possible to do?
      Will it give secure?
      What do you think about? Maybe there is something wrong in this concept or missed.

    • JaredStroeb
      By JaredStroeb
      I need to open an application and send it keys in Session 0.  I have exe's working locally, I can see the application open in session 0 through interactive services, but my send commands do not go to the application.  The following article running-autoit-session-0, directs me to use ControlSend() however my application has no controls that can be identified by AutoIt v3 Window Info.  Get All Windows Controls also returned nothing for the application's handle.  
      What are my options?  
      Can this be done with AutoIt?
      Is there a different "relatively simple" library/tool to use? (I am familiar with C# if there is a viable library there )

       
    • nassausky
      By nassausky
      Hey all,
      Has anyone created any queries for youtube? I was thinking it might be something like this but can't quite figure it out:
      $oIE = _IECreateEmbedded() _IENavigate($oIE,"https://www.youtube.com") Local $oForms = _IETagNameGetCollection($oIE, "form") Local $sTxt = "" For $oForm In $oForms If $oForm.id = "masthead-search" Then $oInputs = _IETagNameGetCollection($oIE, "input") For $oInput In $oInputs If $oInput.id = "masthead-search-term" Then _IEFormElementSetValue($oInput, "cards") _IEFormSubmit($oForm) EndIf Next EndIf Next  
    • Skysnake
      By Skysnake
      Scite comes up occasional, almost incidentally, in some support topics.  I have not found a "Scite" topic in the forums, so this is where I will start.  I have recently been using Scite intensively, specifically with a large project and I have certain issues.  I know that Scite is not an AutoIt product, but it is so closely integrated to the core release that it makes sense to raise issues and request support here.  If this is not the right please refer me to the right forum.
      Thx
       
      Skysnake