Jump to content

Recommended Posts

Posted

Hello,

Checking the help file, Googling, and then searching the archives with "listview list selected rows" didn't help.

I need to loop through the selected rows in a ListView.

It looks like a ListView widget has no notion of rows, and the user is expected to loop through individual selected cells ("items").

Thank you.

While True
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button1
            ConsoleWrite("GetSelectedCount:" & _GUICtrlListView_GetSelectedCount($ListView1) & @CRLF)
            ConsoleWrite("GetSelectedIndices:" & _GUICtrlListView_GetSelectedIndices($ListView1) & @CRLF)
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd
  • Solution
Posted
4 hours ago, littlebigman said:

It looks like a ListView widget has no notion of rows, and the user is expected to loop through individual selected cells ("items").

Nah, the entire row is the item.  Its a 1D list of items rather than a 2D grid. 
Col0 contains the item's text. Col1 contains the text of the item's first sub-item.

 So something like this.

#include <GuiListView.au3>
#include <GuiConstants.au3>

_Main()

Func _Main()
    GUICreate("", 400, 400)
    Local $idButton1 = GUICtrlCreateButton("OK", 400-84, 400 - 28, 80, 24, $BS_DEFPUSHBUTTON)
    Local $idListView1 = GUICtrlCreateListView("Item|SubItem", 4, 4, 400-8, 400-36, $LVS_SHOWSELALWAYS)

    For $i = 0 To 10
        GUICtrlCreateListViewItem("Item" & $i & "|Item " & $i & ", SubItem 1", $idListView1)
    Next

    GUISetState()

    Local $aSelIndices
    While True
        Switch GUIGetMsg()
            Case $idButton1

                ConsoleWrite("GetSelectedCount:" & _GUICtrlListView_GetSelectedCount($idListView1) & @CRLF)
                ConsoleWrite("GetSelectedIndices:" & _GUICtrlListView_GetSelectedIndices($idListView1) & @CRLF)

                $aSelIndices = _GUICtrlListView_GetSelectedIndices($idListView1, True)
                ConsoleWrite("Items Selected: " & @CRLF)
                For $i = 1 To $aSelIndices[0]
                    ConsoleWrite(_GUICtrlListView_GetItemText($idListView1, $aSelIndices[$i], 0) & @CRLF)
                Next
                ConsoleWrite(@CRLF)

            Case $GUI_EVENT_CLOSE
                Exit

        EndSwitch
    WEnd

    GUIDelete()
EndFunc

 

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
×
×
  • Create New...