Solved

VB 2005 code problem

Posted on 2007-11-14
2
175 Views
Last Modified: 2013-11-26
Hi

I am having a problem with the following function that I brought over from VBA into VB 2005
The error is at the line marked 'XXXX and it reads .Selected is not a member of a ListView

    Function sListSelection() As String
        'returns a string separatted by commas of indices selected in a list box
        Dim lngIndex As Long
        Dim S As String
        Dim Count As Long
        Count = 0
        With frmR.lsbActionR
            For lngIndex = 1 To .Items.Count
                If .Selected(lngIndex - 1) Then 'XXXX
                    If Count = 0 Then
                        S = CStr(lngIndex - 1)
                    Else
                        S = S & "," & CStr(lngIndex - 1)
                    End If
                    Count = Count + 1
                End If
            Next lngIndex
        End With
        sListSelection = S
    End Function
0
Comment
Question by:murbro
2 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 500 total points
ID: 20281202
The best way to do this is to use the .SelectedIndices property of the listview which returns a collection containing the selected indices.

Now you could transform that to a string in a similar way:

    Function sListSelection() As String
        'returns a string separatted by commas of indices selected in a list box
        Dim S As String
        With frmR.lsbActionR
            For Each SelectedIndex As Integer In .SelectedIndices
                        S = S & "," & CStr(SelectedIndex)
            Next
        End With
        Return S.Substring(1)
    End Function

Or work directly with the collection.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20281212
try with:
If .Items(IngIndex).Selected Then

but will be better:
Dim Index as Integer
For lngIndex = 1 To .SelectedIndices.Count
                   Index = SelectedIndices(IngIndex)
                    If Count = 0 Then
                        S = CStr(Index - 1)
                    Else
                        S = S & "," & CStr(Index - 1)
                    End If
                    Count = Count + 1
Next lngIndex
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question