Need help with listview

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 1727 Views - Last Post: 29 July 2010 - 03:00 PM Rate Topic: -----

#1 qtex  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 142
  • Joined: 24-October 09

Need help with listview

Posted 28 July 2010 - 04:22 PM

Hello,

I'm trying to make MP3 player with listview but I have some problems what I cant figure out.
First problem is that when I import files then every song should get number. Its like play list up to down with number 1,2,3,4,5 etc. I tryed to google but I didn't find anything useful. Mabye because I don't know how to name that.
Second problem is that I don't know how to get song length.
Third problem : when I play a song I want that it add +1 for Times Played , but I don't know how to add it parallel with right song.
I'm using AxWindowsMediaPlayer to make this.
Mabye anyone can help me with it ?

Picture to understand better:
]Posted Image


thanks,

This post has been edited by qtex: 28 July 2010 - 04:25 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Need help with listview

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Need help with listview

Posted 28 July 2010 - 05:01 PM

So what have you got so far?
There's a lot of steps to get from the picture you've shown to the end result and as per forum rules, you need to display an effort on your part.
Was This Post Helpful? 0
  • +
  • -

#3 qtex  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 142
  • Joined: 24-October 09

Re: Need help with listview

Posted 28 July 2010 - 05:06 PM

View PostCharlieMay, on 28 July 2010 - 04:01 PM, said:

So what have you got so far?
There's a lot of steps to get from the picture you've shown to the end result and as per forum rules, you need to display an effort on your part.


I have some code so far and I don't expect that somebody do code for me. I expect that somebody help me functions or give some link where to read it or look for it.

Here is my Import code :

Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
        For Each track As String In OpenFileDialog1.FileNames
            Dim str(3) As String
            Dim itm As ListViewItem
            str(0) = track
            str(1) = "" <- song ID must come here
            str(2) = "" <- song lenth must come here
            itm = New ListViewItem(str)
            ListView1.Items.Add(itm)
        Next
    End Sub


Play button code is here :

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        AxWindowsMediaPlayer1.URL = ListView1.FocusedItem.Text
    End Sub

Was This Post Helpful? 0
  • +
  • -

#4 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Need help with listview

Posted 28 July 2010 - 05:16 PM

So upon clicking the button to play you can increment the times played by getting the number stored in the times played column and then adding 1 to it and writing the new value back

ListView1.FocusedItem.SubItems(3).Text = Convert.ToString(convert.toint32(listview1.focuseditem.subitems(3).Text) + 1)


If you are generating your own ID you can just use the following:
Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
dim SongID as integer = 0
        For Each track As String In OpenFileDialog1.FileNames
            Dim str(3) As String
            SongID +=1
            Dim itm As ListViewItem
            str(0) = track
            str(1) = SongID.ToString <- song ID must come here
            str(2) = "" <- song lenth must come here
            itm = New ListViewItem(str)
            ListView1.Items.Add(itm)
        Next

End Sub

Edited: Missed a conversion back to string.

This post has been edited by CharlieMay: 28 July 2010 - 05:26 PM

Was This Post Helpful? 1
  • +
  • -

#5 qtex  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 142
  • Joined: 24-October 09

Re: Need help with listview

Posted 28 July 2010 - 05:37 PM

View PostCharlieMay, on 28 July 2010 - 04:16 PM, said:

So upon clicking the button to play you can increment the times played by getting the number stored in the times played column and then adding 1 to it and writing the new value back

ListView1.FocusedItem.SubItems(3).Text = Convert.ToString(convert.toint32(listview1.focuseditem.subitems(3).Text) + 1)


If you are generating your own ID you can just use the following:
Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
dim SongID as integer = 0
        For Each track As String In OpenFileDialog1.FileNames
            Dim str(3) As String
            SongID +=1
            Dim itm As ListViewItem
            str(0) = track
            str(1) = SongID.ToString <- song ID must come here
            str(2) = "" <- song lenth must come here
            itm = New ListViewItem(str)
            ListView1.Items.Add(itm)
        Next

End Sub

Edited: Missed a conversion back to string.


ListView1.FocusedItem.SubItems(3).Text = Convert.ToString(convert.toint32(listview1.focuseditem.subitems(3).Text) + 1)


It's very smart idea, but If I'll press the Play button it will unfocus item and VB shows error. How is possible to fix it ?

Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
dim SongID as integer = 0
        For Each track As String In OpenFileDialog1.FileNames
            Dim str(3) As String
            SongID +=1
            Dim itm As ListViewItem
            str(0) = track
            str(1) = SongID.ToString <- song ID must come here
            str(2) = "" <- song lenth must come here
            itm = New ListViewItem(str)
            ListView1.Items.Add(itm)
        Next
    End Sub


With that code all song comes with Song ID 1. Something is wrong but I cant figure out what is wrong.
Was This Post Helpful? 0
  • +
  • -

#6 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Need help with listview

Posted 28 July 2010 - 05:56 PM

What is the error. The listview will still have a focused item even when you click the button so I may have an index wrong.

As far as the second part, let me look at it and see what I've missed.
Was This Post Helpful? 0
  • +
  • -

#7 qtex  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 142
  • Joined: 24-October 09

Re: Need help with listview

Posted 28 July 2010 - 06:02 PM

View PostCharlieMay, on 28 July 2010 - 04:56 PM, said:

What is the error. The listview will still have a focused item even when you click the button so I may have an index wrong.

Error : Input string was not in a correct format.
Was This Post Helpful? 0
  • +
  • -

#8 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Need help with listview

Posted 28 July 2010 - 06:02 PM

OK, as far as the first error, you need to create a str(3) = "0" and increase your array to 4. My code assumed a numeric value in the Times Played column.

I'm getting an incremented counter when I select multiple files. Are you sure you put the dim statement outside the for each?

This post has been edited by CharlieMay: 28 July 2010 - 06:06 PM

Was This Post Helpful? 1
  • +
  • -

#9 qtex  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 142
  • Joined: 24-October 09

Re: Need help with listview

Posted 28 July 2010 - 06:07 PM

View PostCharlieMay, on 28 July 2010 - 05:02 PM, said:

OK, as far as the first error, you need to create a str(3) = "0" and increase your array to 4. My code assumed a numeric value in the Times Played column.

I'm getting an incremented counter when I select multiple files. Are you sure you put the dim statement outside the for each?


Thank you ! That thing I got working
Was This Post Helpful? 0
  • +
  • -

#10 qtex  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 142
  • Joined: 24-October 09

Re: Need help with listview

Posted 29 July 2010 - 01:28 PM

Hello,

I have little problem / question again. This time with that code :

 Static Index As Integer = 0
        If AxWindowsMediaPlayer1.playState = _
        WMPLib.WMPPlayState.wmppsReady Or _
        AxWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsUndefined Or _
        AxWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsStopped Then
            If ListView1.Items.Count > 0 Then
                AxWindowsMediaPlayer1.currentMedia = AxWindowsMediaPlayer1.newMedia(ListView1.FocusedItem.Index(Index))
                Index += 1
                If Index > ListView1.Items.Count - 1 Then
                    Index = 0
                End If
            End If
        End If

AxWindowsMediaPlayer1.newMedia(ListView1.FocusedItem.Index(Index))
Problem is with that bold text

thanks

This post has been edited by qtex: 29 July 2010 - 01:31 PM

Was This Post Helpful? 0
  • +
  • -

#11 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Need help with listview

Posted 29 July 2010 - 01:40 PM

It this supposed to pass the name of the file? ListView1.FocusedItem.Text??? maybe...
Was This Post Helpful? 0
  • +
  • -

#12 qtex  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 142
  • Joined: 24-October 09

Re: Need help with listview

Posted 29 July 2010 - 01:53 PM

View PostCharlieMay, on 29 July 2010 - 12:40 PM, said:

It this supposed to pass the name of the file? ListView1.FocusedItem.Text??? maybe...


nop I already tryed this. It will give error. Error : Exception from HRESULT: 0xC00D1327

I have a better idea but how I can do that it select next item itself ?

This post has been edited by qtex: 29 July 2010 - 02:14 PM

Was This Post Helpful? 0
  • +
  • -

#13 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Need help with listview

Posted 29 July 2010 - 02:38 PM

Well, you could get the current index that you're on in the listview. Set the focus to the next index and then send a btnPlay.PerformClick to make the program simulate the buttonclick.
Was This Post Helpful? 1
  • +
  • -

#14 qtex  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 142
  • Joined: 24-October 09

Re: Need help with listview

Posted 29 July 2010 - 02:47 PM

View PostCharlieMay, on 29 July 2010 - 01:38 PM, said:

Well, you could get the current index that you're on in the listview. Set the focus to the next index and then send a btnPlay.PerformClick to make the program simulate the buttonclick.


Thanks , but I already done this with other way. Now I got all things to work what I needed. So thanks again !
Was This Post Helpful? 0
  • +
  • -

#15 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Need help with listview

Posted 29 July 2010 - 02:56 PM

Great, glad you got it working. You should post your solution so that others with the same types of questions can use it to learn from.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2