6 Replies - 1189 Views - Last Post: 17 January 2011 - 05:56 PM Rate Topic: -----

#1 Tomas86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 17-January 11

Play Next File in ListView

Posted 17 January 2011 - 03:18 PM

Hi guys don't know if you will reply to this but i have looked all over the internet for a code like this and was hoping you would be able to help. This code works a treat so i will not re-post it but i am having a problem where if the code gets to the last listview.index it errors. How do i get it to go back to the start and for the when it reaches the top (previous) to start at the bottom.

Here is the modded code to go back
        Dim x As Integer = lvPlaylist.SelectedIndices(0)
        lvPlaylist.Items(x).Selected = False
        lvPlaylist.Items(x - 1).Selected = True
        lvPlaylist.Select()
        AxcPlayer1.OpenMedia(lvPlaylist.SelectedItems(0).SubItems(3).Text)
        AxcPlayer1.MediaPlay()



Thanks in advance

Is This A Good Question/Topic? 0
  • +

Replies To: Play Next File in ListView

#2 dawmail333  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 27
  • View blog
  • Posts: 174
  • Joined: 02-July 07

Re: Play Next File in ListView

Posted 17 January 2011 - 03:32 PM

View PostTomas86, on 18 January 2011 - 08:18 AM, said:

Hi guys don't know if you will reply to this but i have looked all over the internet for a code like this and was hoping you would be able to help. This code works a treat so i will not re-post it but i am having a problem where if the code gets to the last listview.index it errors. How do i get it to go back to the start and for the when it reaches the top (previous) to start at the bottom.

Here is the modded code to go back
        Dim x As Integer = lvPlaylist.SelectedIndices(0)
        lvPlaylist.Items(x).Selected = False
        lvPlaylist.Items(x - 1).Selected = True
        lvPlaylist.Select()
        AxcPlayer1.OpenMedia(lvPlaylist.SelectedItems(0).SubItems(3).Text)
        AxcPlayer1.MediaPlay()



Thanks in advance



Add (after Dim x As Integer):
If x = 0 Then Exit Sub


In case of the original code:
If x + 1 = listview1.Items.Count

If that doesn't work, replace count with length. It's one of the two xD
Was This Post Helpful? 1
  • +
  • -

#3 Tomas86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 17-January 11

Re: Play Next File in ListView

Posted 17 January 2011 - 03:49 PM

ok so i have dont the following

        Dim x As Integer = lvPlaylist.SelectedIndices(0)
        If x + 1 = lvPlaylist.Items.Count Then
            lvPlaylist.Items(x).Selected = False
            lvPlaylist.Items(0).Selected = True
            lvPlaylist.Select()
            AxcPlayer1.OpenMedia(lvPlaylist.SelectedItems(0).SubItems(3).Text)
            AxcPlayer1.MediaPlay()
        Else
            lvPlaylist.Items(x).Selected = False
            lvPlaylist.Items(x + 1).Selected = True
            lvPlaylist.Select()
            AxcPlayer1.OpenMedia(lvPlaylist.SelectedItems(0).SubItems(3).Text)
            AxcPlayer1.MediaPlay()
        End If



i even tried the following


        Dim x As Integer = lvPlaylist.SelectedIndices(0)
        Dim i As Integer = lvPlaylist.Items.Count
        If i = 0 Then
            lvPlaylist.Items(x).Selected = False
            lvPlaylist.Items(0).Selected = True
            lvPlaylist.Select()
            AxcPlayer1.OpenMedia(lvPlaylist.SelectedItems(0).SubItems(3).Text)
            AxcPlayer1.MediaPlay()
        Else
            lvPlaylist.Items(x).Selected = False
            lvPlaylist.Items(x + 1).Selected = True
            lvPlaylist.Select()
            AxcPlayer1.OpenMedia(lvPlaylist.SelectedItems(0).SubItems(3).Text)
            AxcPlayer1.MediaPlay()
            i = i - 1
        End If


and it does not do any thing as i am trying to get it to go to the first index in the list

This post has been edited by Tomas86: 17 January 2011 - 03:55 PM

Was This Post Helpful? 0
  • +
  • -

#4 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1623
  • View blog
  • Posts: 5,196
  • Joined: 25-September 09

Re: Play Next File in ListView

Posted 17 January 2011 - 04:03 PM

Try this
        Dim x As Integer = lvPlaylist.SelectedIndices(0)
        lvPlaylist.Items(x).Selected = False
        If x + 1 > lvPlaylist.items.count - 1 Then
            x = -1
        End If
        lvPlaylist.Items(x + 1).Selected = True
        lvPlaylist.Select()
        AxcPlayer1.OpenMedia(lvPlaylist.SelectedItems(0).SubItems(3).Text)
        AxcPlayer1.MediaPlay()


This will move down the list and then back to the top to start again.
Was This Post Helpful? 1
  • +
  • -

#5 Tomas86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 17-January 11

Re: Play Next File in ListView

Posted 17 January 2011 - 04:11 PM

Thanks guys i know this can be annoying.

Now i am having errors trying to put the code in reverse

        Dim x As Integer = lvPlaylist.SelectedIndices(0)
        lvPlaylist.Items(x).Selected = False
        If x - 1 > lvPlaylist.Items.Count - 1 Then
            x = lvPlaylist.Items.Count + 1
        End If
        lvPlaylist.Items(x - 1).Selected = True
        lvPlaylist.Select()
        AxcPlayer1.OpenMedia(lvPlaylist.SelectedItems(0).SubItems(3).Text)
        AxcPlayer1.MediaPlay()



Gives me an error saying

InvalidArgument=Value of '-1' is not valid for 'index'.
Parameter name: index
Was This Post Helpful? 0
  • +
  • -

#6 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1623
  • View blog
  • Posts: 5,196
  • Joined: 25-September 09

Re: Play Next File in ListView

Posted 17 January 2011 - 05:45 PM

This is nothing but numbers. Your listview starts at index 0 and has a maximum index of the count-1 therefore you just need to check if you are at the 0 index and if so, set the new index to the count. Why just the count, because that is one more than your last index and since you are selecting items(x-1) that will put you at the last index.

Dim x As Integer = lvPlaylist.SelectedIndices(0)
lvPlaylist.Items(x).Selected = False
If x = 0  Then
    x = lvPlaylist.Items.Count 
End If
lvPlaylist.Items(x - 1).Selected = True
lvPlaylist.Select()
AxcPlayer1.OpenMedia(lvPlaylist.SelectedItems(0).SubItems(3).Text)
AxcPlayer1.MediaPlay()


Was This Post Helpful? 1
  • +
  • -

#7 Tomas86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 17-January 11

Re: Play Next File in ListView

Posted 17 January 2011 - 05:56 PM

I want to thank you both so much for the help..

so THANKS.

Tomas
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1