Solved

stop at the end

Posted on 2007-03-19
9
144 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
  • 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 51

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 51

Expert Comment

by:Ryan Chong
ID: 18746855
I thought the Index property should start from 1, not 0?
0
Independent Software Vendors: 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!

 
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 51

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
clicking a shape in a frame array vb6 3 48
Help me. 3 69
Problem to With line 4 74
converting visio 2010 to powerpoint 2010  - formatting issues 5 108
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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 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…

740 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