Results 1 to 8 of 8

Thread: Next Items ....Help

  1. #1
    Encrypted-w is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    Mar 2011
    Posts
    17
    Reputation
    30

    Unhappy Next Items ....Help

    Hi all
    How to Go to the following items in the listview automatically ?
    This example does not work with me
    PHP Code:
    Private Sub Timer2_Tick(ByVal sender As System.ObjectByVal e As System.EventArgsHandles Timer2.Tick
            ListView1
    .MultiSelect False
            
    For 0 To ListView1.SelectedItems.Count 1
                I 
    = +1
                ListView1
    .Items(I).Selected True
            Next I
        End Sub 

  2. #2
    Ehsanit is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 4.0
    Join Date
    Feb 2011
    Posts
    80
    Reputation
    55
    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.
    Code:
    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

  3. #3
    Encrypted-w is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    Mar 2011
    Posts
    17
    Reputation
    30
    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
    Quote Originally Posted by Ehsanit View Post
    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.
    Code:
    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

  4. #4
    Ehsanit is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 4.0
    Join Date
    Feb 2011
    Posts
    80
    Reputation
    55
    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)

  5. #5
    Encrypted-w is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    Mar 2011
    Posts
    17
    Reputation
    30
    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

  6. #6
    Ehsanit is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 4.0
    Join Date
    Feb 2011
    Posts
    80
    Reputation
    55
    Does this fix it?
    Code:
        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

  7. #7
    Encrypted-w is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    Mar 2011
    Posts
    17
    Reputation
    30
    yes . now it is true
    I am very happy
    Thank you very very Much
    Quote Originally Posted by Ehsanit View Post
    Does this fix it?
    Code:
        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

  8. #8
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,197
    Reputation
    2368
    Instead of forcing the Listview to be selected when or if it is not you can set this property in designer to have it display selection regardless: ListView.HideSelection Property (System.Windows.Forms)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking