[Solved] Listview add subitems, more problems

Adding ListView.Subitems within a loop

Page 1 of 1

2 Replies - 14955 Views - Last Post: 08 March 2009 - 05:08 AM Rate Topic: -----

#1 Tertitten  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 02-March 09

[Solved] Listview add subitems, more problems

Posted 08 March 2009 - 02:43 AM

This is now solved, the correct code was
	Private Sub tvFolders1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvFolders1.AfterSelect
		Dim id3folder As String
		id3folder = e.Node.FullPath()
		Dim objMP3Info As New _
		Monotic.Multimedia.MP3.MP3Info()
		files = FileIO.FileSystem.GetFiles(id3folder, FileIO.SearchOption.SearchAllSubDirectories, "*.mp3")		
		For Each a As String In files
			With lvFiles.Items.Add(FileIO.FileSystem.GetName(a))
				objMP3Info.Filename = (FileIO.FileSystem.GetParentPath(a) + "\" + FileIO.FileSystem.GetName(a))
				'MessageBox.Show(objMP3Info.Filename)
				If (objMP3Info.ID3v1Tag.TagAvailable) Then
					.SubItems.Add(objMP3Info.ID3v1Tag.Title)
					.SubItems.Add(objMP3Info.ID3v1Tag.Artist) ' Title
					.SubItems.Add(objMP3Info.ID3v1Tag.Album) ' Title
					.SubItems.Add(objMP3Info.ID3v1Tag.Genre) ' Title
					.SubItems.Add(objMP3Info.ID3v1Tag.Year) ' Title
					.SubItems.Add(objMP3Info.ID3v1Tag.Title.Length) ' Title
					' Source  -- Title -- Artist -- Album -- Genre -- Year -- Length
				End If
			End With
		Next
	End Sub


I'm now trying a different approuch to my previous problem with the TreeView/ListView issue I had, this new "sollution" seems to be a bit more easy however I still can't solve it.

The problem is to add the remaining listview.subitems, everything I try ether
a: crashes app, or
b: Only adds one subitem.
If you take a look at the code you should see where my problem is, I where really hoping someone could help me solving it.
	Private Sub tvFolders1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvFolders1.AfterSelect
		Dim id3folder As String
		id3folder = e.Node.FullPath()
		Dim objMP3Info As New _
		Monotic.Multimedia.MP3.MP3Info()
		files = FileIO.FileSystem.GetFiles(id3folder, FileIO.SearchOption.SearchAllSubDirectories, "*.mp3")
		'_U = Val(files)
		For Each a As String In files
			With lvFiles
				objMP3Info.Filename = (FileIO.FileSystem.GetParentPath(a) + "\" + FileIO.FileSystem.GetName(a))				
				'MessageBox.Show(objMP3Info.Filename)
				If (objMP3Info.ID3v1Tag.TagAvailable) Then
					lvFiles.Items.Add(FileIO.FileSystem.GetName(a)).SubItems.Add _
					(objMP3Info.ID3v1Tag.m_strTitle)

				   ' I need to know the next stem for adding next subitem here, 
				   ' I've tried with everything I've come up with so far (Integers etc) but
				   ' to no avail
					lvFiles.Items(.Columns.(e)).SubItems.Add(objMP3Info.ID3v1Tag.m_strTitle)
				End If
				
				'MessageBox.Show(objMP3Info.ID3v1Tag.Title)
			End With
		Next

	End Sub


This post has been edited by Tertitten: 08 March 2009 - 04:23 AM


Is This A Good Question/Topic? 0
  • +

Replies To: [Solved] Listview add subitems, more problems

#2 Tertitten  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 02-March 09

Re: [Solved] Listview add subitems, more problems

Posted 08 March 2009 - 04:10 AM

Ok, so I've come a step further of solving this, no crashes now, however it adds all in the wrong places, so I'm still doing something wrong...

Edit: Actually it adds the number 1 on every second item with no subitem loaded, so apparently i'm doing something very wrong with adding Items, not Subitems, these are now added correctly

Here is the code I've got now, hopefully some of you can spot what I'm doing wrong
	Private Sub tvFolders1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvFolders1.AfterSelect
		Dim id3folder As String
		Dim _U As Integer
		id3folder = e.Node.FullPath()
		Dim objMP3Info As New _
		Monotic.Multimedia.MP3.MP3Info()
		files = FileIO.FileSystem.GetFiles(id3folder, FileIO.SearchOption.SearchAllSubDirectories, "*.mp3")		
		For Each a As String In files
			_U = +1
			lvFiles.Items.Add(FileIO.FileSystem.GetName(a))
			With lvFiles.Items.Add(_U)
				objMP3Info.Filename = (FileIO.FileSystem.GetParentPath(a) + "\" + FileIO.FileSystem.GetName(a))
				'MessageBox.Show(objMP3Info.Filename)
				If (objMP3Info.ID3v1Tag.TagAvailable) Then
					.SubItems.Add(objMP3Info.ID3v1Tag.Title)
					.SubItems.Add(objMP3Info.ID3v1Tag.Artist) ' Title
					.SubItems.Add(objMP3Info.ID3v1Tag.Album) ' Title
					.SubItems.Add(objMP3Info.ID3v1Tag.Genre) ' Title
					.SubItems.Add(objMP3Info.ID3v1Tag.Year) ' Title
					.SubItems.Add(objMP3Info.ID3v1Tag.Title.Length) ' Title
					.SubItems.Add(objMP3Info.ID3v1Tag.Artist) ' Title
					' Source  -- Title -- Artist -- Album -- Genre -- Year -- Length
				End If
				'MessageBox.Show(objMP3Info.ID3v1Tag.Title)
			End With
		Next
	End Sub

This post has been edited by Tertitten: 08 March 2009 - 04:19 AM

Was This Post Helpful? 0
  • +
  • -

#3 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,500
  • Joined: 29-May 08

Re: [Solved] Listview add subitems, more problems

Posted 08 March 2009 - 05:08 AM

This bit
For Each a As String In files
_U = +1


should be
For Each a As String In files
_U  +=1


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1