Solved

stop at the end

Posted on 2007-03-19
9
148 Views
Last Modified: 2010-04-30
this is what im using to select the next record from my listview
but how can I make something so it wont keep trying to
select more when it gets to the end?

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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
9 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 18746847
Check for Count - 1:

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

The last item in the listview is .ListItems.Count -1 so if it is less than that there will be one more to select. If it is the last one then no more will be selected.
0
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 18746850
what is mean by "select more when it gets to the end" ?

above sample should works without any error.
0
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 18746855
I thought the Index property should start from 1, not 0?
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 43

Expert Comment

by:TimCottee
ID: 18746859
Good question, I can't remember right now. I though the index property was from 0 to .Count -1 it is with the listbox, can't be certain from memory on the listview though. If it is zero based then need to use .Count - 1 otherwise as you say it should work as is.
0
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 18746866
cheers Tim ; )
0
 

Author Comment

by:Sabrin
ID: 18746885
so whats the correct code?
0
 

Author Comment

by:Sabrin
ID: 18746896
like this?

If .SelectedItem.Index < .ListItems.Count - 0 And .ListItems.Count > 1 Then
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 500 total points
ID: 18746907
As I showed you assuming that the .index propery starts at zero and not 1.

            If .SelectedItem.Index < .ListItems.Count - 1 And .ListItems.Count > 1 Then
0
 

Author Comment

by:Sabrin
ID: 18746928
with this line it stops 1 before the end

If .SelectedItem.Index < .ListItems.Count - 1 And .ListItems.Count > 1 Then
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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month7 days, 1 hour left to enroll

623 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