Next Items ....Help

Encrypted-w

Member
Joined
Mar 1, 2011
Messages
17
Programming Experience
Beginner
Hi all
How to Go to the following items in the listview automatically ?
This example does not work with me
PHP:
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        ListView1.MultiSelect = False
        For I = 0 To ListView1.SelectedItems.Count - 1
            I = +1
            ListView1.Items(I).Selected = True
        Next I
    End Sub
 
In the first place if you want to add one to a variable it is I += 1, not I= +1.
If you want it to move down the list box every time the timer ticks, you don't want that for loop, it (ignoring the I = +1 line) will run through all entries every time. Because you're changing I in the middle it won't even do that.

A better solution if that's your objective would involve declaring I outside the subroutine, and doing away with the for loop.
VB.NET:
Dim I as integer = 0
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
    ListView1.MultiSelect = False
        I += 1
        If I = ListView1.SelectedItems.Count then I = 0
        ListView1.Items(I).Selected = True
    End Sub

You don't need the
ListView1.MultiSelect = False
line within the timer sub unless something is setting that to true elsewhere in the code. It's better to put it where it will execute once in setting up the program, such as on Load or simply adjusting the relevant property of ListView1
 
Thank you for your reply
but your Example does not work with me
I would like to move from item to the next item in a certain time
see this the picture
UWVxO.png
In the first place if you want to add one to a variable it is I += 1, not I= +1.
If you want it to move down the list box every time the timer ticks, you don't want that for loop, it (ignoring the I = +1 line) will run through all entries every time. Because you're changing I in the middle it won't even do that.

A better solution if that's your objective would involve declaring I outside the subroutine, and doing away with the for loop.
VB.NET:
Dim I as integer = 0
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
    ListView1.MultiSelect = False
        I += 1
        If I = ListView1.SelectedItems.Count then I = 0
        ListView1.Items(I).Selected = True
    End Sub

You don't need the
ListView1.MultiSelect = False
line within the timer sub unless something is setting that to true elsewhere in the code. It's better to put it where it will execute once in setting up the program, such as on Load or simply adjusting the relevant property of ListView1
 
You say it doesn't work, but what is actually happening?
Have you checked that the timer is set to 2 seconds (set to 2000) and that it is enabled (they default to enabled=false)
 
The problem is not at the time. But in the transition from one item to the next item
In your example. Can not move to the next item, but remains in the first item
 
Does this fix it?
VB.NET:
    Dim I As Integer = 0
    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        ListView1.MultiSelect = False
        I += 1
        If I = ListView1.Items.Count Then I = 0
        ListView1.Items(I).Selected = True
        ListView1.Select()
    End Sub
 
:) yes . now it is true
I am very happy
Thank you very very Much :D
Does this fix it?
VB.NET:
    Dim I As Integer = 0
    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        ListView1.MultiSelect = False
        I += 1
        If I = ListView1.Items.Count Then I = 0
        ListView1.Items(I).Selected = True
        ListView1.Select()
    End Sub
 
Back
Top