getting values for multiple selections on a listview

Started by Shawn Anderson, May 10, 2013, 01:39:52 PM

Previous topic - Next topic

Shawn Anderson

I want to get the values of multiple selected items in an listview.

I can get how many rows are selected using
nor= ListView_GetSelectedCount(HWND_BU_ROUTERLIST)   

But how do I know the index # of which rows are selected?

On another note, I tried to do
LISTVIEW Get Count hWndForm, HWND_BU_ROUTERLIST To nor
but it always returns 0.
why?

thanks

Carl Oligny

Hi Shawn,

On item #2 - I have not used the PB syntax in a while, but the problem may be with the 2nd parameter. It should be the id of the control. Looks like you may be passing the FF hwndControl value.

I always use the FF function - nor = FF_ListView_GetItemCount(HWND_BU_ROUTERLIST) - 1

I am running F3.62 but don't see the  ListView_GetSelectedCount function in the library. Guess I need to add it manually.

If you iterate through the rows you could use the PB function:

LISTVIEW GET SELECT hDlg, id& [, item&] TO datav&

Use this to get subitems:
LISTVIEW GET STATE hDlg, id&, item&, col& TO datav&


Jean-pierre Leroy

Hi Shawn,

First of all you need to be sure that at least one line is selected; and then you can use the function ListView_SelectedIndexs() below to retrieve a list of all the selected indexs of a listview in string separated by a comma; using PARSECOUNT and PARSE$ functions you can do whatever you want with the different selected lines of the listview:


LOCAL ListOfSelectedIndexs AS STRING
LOCAL lI                           AS LONG
LOCAL lIndex                     AS LONG

IF ListView_GetSelectedCount(hWndControl) >= 1 THEN

    ListOfSelectedIndexs = ListView_SelectedIndexs(hWndControl)

    FOR lI = 1 TO PARSECOUNT(ListOfSelectedIndexs)
          lIndex = VAL(PARSE$(ListOfSelectedIndexs, lI))
          ' DO WHATEVER YOU WANT WITH THIS SELECTED LINE
    NEXT lI

END IF


Here is the function ListView_SelectedIndexs that you can add to the Functions Library.


Function ListView_SelectedIndexs(ByVal hWndListView As Dword) As String         

    Local lIndex  As Long   
    Local lIndexs As String
   
    lIndex = -1           
    Do           
   
        ' to get the next selected index
        lIndex = ListView_GetNextItem (hWndListView, lIndex, %LVNI_SELECTED)
       
        ' if we get the next index
        If lIndex <> -1 Then                   
           
            ' to prepare the string with all the indexs separated by a comma
            lIndexs = lIndexs+Format$(lIndex)+","
           
        End If                   
                     
    Loop Until lIndex = -1
   
    ' to remove the last ","
    Function = Left$(lIndexs, -1)
           
End Function


Jean-Pierre