Solved

loop from listview

Posted on 2007-03-19
2
209 Views
Last Modified: 2012-06-21
this is what im using to select the next record from my listview
but how can I make something so when it gets to the end
it goes back to the first record?

Private Sub SelectNextOne()
    With lvwMain
        If Not .SelectedItem Is Nothing Then
            If .SelectedItem.Index < .ListItems.Count And .ListItems.Count > 1 Then
                .ListItems(.SelectedItem.Index + 1).Selected = True
            End If
        End If
    End With
End Sub
0
Comment
Question by:Sabrin
2 Comments
 
LVL 6

Expert Comment

by:saravananvg
ID: 18746883
Hello Sir,

  I think the condition should be
 if .SelectedItem.Index <= ListItems.Count -1 And .ListItems.Count > 1

with regards,
padmaja.
0
 
LVL 26

Accepted Solution

by:
EDDYKT earned 500 total points
ID: 18747193
Try this


Private Sub SelectNextOne()
    With lvwMain
        If Not .SelectedItem Is Nothing Then
            If .SelectedItem.Index < .ListItems.Count And .ListItems.Count > 1 Then
                .ListItems(.SelectedItem.Index + 1).Selected = True
            Else
                .ListItems(1).Selected = True
            End If
        End If
        .SetFocus
    End With
End Sub
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

733 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