Jump to content

Get Listview content issue


Valnurat
 Share

Recommended Posts

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.

Link to comment
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)

 

Link to comment
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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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

×
×
  • Create New...