Jump to content

[Solved] Problem with ListView UDF _AddArray function


qwert
 Share

Recommended Posts

I've worked with ListView functions for years, but now it appears that the methods I've used have masked problems with some of the UDF's basic features.

What I've concluded is that proper operation of the UDF depends on how you populate the view.

If you add list entries one at a time, using standard functions, then all the item fetch features work.

But it you populate using the _AddArray function, the item fetch features don't work—even though the ListView displays just fine.

What masked the problems was that although my previous scripts were getting the current row from the ListView, they were going back and fetching contents from the posted array. In other words, I was never using ListView's fetch features.

Now, I've started using features that manipulate the contents of the view, so I need to rely on the UDF's "get content" features.

The following is a simple example. The get current row function works, but the fetch corresponding text function doesn't.

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>

Example()

Func Example()

; Create GUI
    GUICreate("ListView Add Array", 400, 300)
    $idListview = GUICtrlCreateListView("", 2, 2, 394, 268)
    $idButton = GUICtrlCreateButton("get subitem", 160, 272, 100, 22)
    GUISetState(@SW_SHOW)

; Add columns
    _GUICtrlListView_AddColumn($idListview, "Items", 100)
    _GUICtrlListView_AddColumn($idListview, "SubItems 1", 100)
    _GUICtrlListView_AddColumn($idListview, "SubItems 2", 100)
    _GUICtrlListView_AddColumn($idListview, "SubItems 3", 100)

    _GUICtrlListView_SetItemCount($idListview, 50)

; Four column load
Local $aItems[50][4]
    For $iI = 0 To UBound($aItems) - 1
        $aItems[$iI][0] = "Item " & $iI
        $aItems[$iI][1] = "Item " & $iI & "-1"
        $aItems[$iI][2] = "Item " & $iI & "-2"
        $aItems[$iI][3] = "Item " & $iI & "-3"
    Next
    _GUICtrlListView_AddArray($idListview, $aItems)

;~  ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

    Case $idButton
        Local $row = _GUICtrlListView_GetSelectedIndices($idListview)
                MsgBox(0, "listview row", $row, 1)
        Local $cSelected = _GUICtrlListView_GetItemText($idListview, $row, 2) ; subitem 2
                MsgBox(0, "listview item", $cSelected, 0)

        EndSwitch
    WEnd
EndFunc   ;==>Example

I can only think that maybe I've missed setting some essential parameter after I've populated the array. Otherwise, I suppose my use is just a fringe case that the UDF was never intended to support. But which?

Any assistance will be greatly appreciated.

 

(BTW, I'm using the recommended latest UDF version, 3.3.14.5, on an up-to-date Win10 PC.)

 

Edited by qwert
Link to comment
Share on other sites

Hi qwert :)

Just change this :

Local $cSelected = _GUICtrlListView_GetItemText($idListview, $row , 2) ; subitem 2

with that :

Local $cSelected = _GUICtrlListView_GetItemText($idListview, Number($row) , 2) ; subitem 2

This is because GUICtrlListView_GetSelectedIndices() returned a string, not a number.

Also, it's great you use _GUICtrlListView_AddArray() to populate the Listview because it's a fast function (it uses loops inside the function) compared to other ways for populating the LV

Edited by pixelsearch
Some words about _GUICtrlListView_AddArray()
Link to comment
Share on other sites

pixelsearch, that is a insightful bit of knowledge: Number($row)

I don't recall ever seeing or thinking about such a difference. I guess I've been spoiled by the ways AutoIt bridges over the differences between strings and integers.

Thanks very much.

"Problem solved!"

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