locked
ListView remove blank items RRS feed

  • Question

  • I have a listview called listview1
    i have 2 column
        -Column 1 names Songs labeled Songs
        -Column 2 named Favorited labeled Favorites
    i have on the listview that it has a Contextmenustrip and when i right click it will add it to the column 2 named Favorites
    I have this code so far:
    ListView1.Items.Add(New ListViewItem({ListView1.SelectedItems(0).Text}))
    It adds a blank item into column 1, and also adds an item into column 2
    I was wondering If I could add code to delete the first item added in the first column
    Any help would be appreciated!
    Sunday, November 10, 2013 7:25 PM

Answers

  • Hi,

     I am not sure but, maybe this will help. I add a few fake song names to the listview and have a contextmenu that has (Add to Favorites) and (Remove From Favorites) . When you right click on an item it tests the text in the 2nd column to set the proper menu item states on the contextmenu. You can add the text from the first column to the 2nd column and then remove it from the 1st column. Then it does the reverse if you remove it from the 2nd column. You can test it quick by creating a new Form project and add 1 ListView to it. Don`t set any properties. Now copy the code below to the forms code. I tried to explain a little in the code so maybe you can understand it better.

    Public Class Form1
        'This creates a new ContextMenuStrip and 2 MenuItems AddToFav and RemoveFav for it.
        Dim WithEvents cms As New ContextMenuStrip
        Dim WithEvents AddToFav As New ToolStripMenuItem With {.Text = "Add To Faforites"}
        Dim WithEvents RemoveFav As New ToolStripMenuItem With {.Text = "Remove From Favorites"}
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'These listview properties can be set on the form [Design] tab instead of here in the code
            ListView1.View = View.Details
            ListView1.FullRowSelect = True
            ListView1.ContextMenuStrip = cms
            ListView1.HeaderStyle = ColumnHeaderStyle.Nonclickable
            ListView1.Columns.Add("Song Name", 100, HorizontalAlignment.Left)
            ListView1.Columns.Add("Favorites", 100, HorizontalAlignment.Left)
    
            cms.Items.Add(AddToFav) 'Adds the ToolStripMenuItems to the ContextMenuStrip
            cms.Items.Add(RemoveFav)
    
            'I just used this loop to fake loading song names into the listview
            For x As Integer = 0 To 5
                Dim lvi As New ListViewItem("Song - " & x.ToString)
                lvi.SubItems.Add("") 'Add an empty string if no text is going in the subitem (Favorites column)
                ListView1.Items.Add(lvi)
            Next
        End Sub
    
        Private Sub AddToFav_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddToFav.Click
            'Set the Favorites column text to the text that is in the SongName column for the selected item
            ListView1.SelectedItems(0).SubItems(1).Text = ListView1.SelectedItems(0).Text
    
            'If you want to remove the text from SongName column when adding it to the Favorites column
            ListView1.SelectedItems(0).Text = ""
        End Sub
    
        Private Sub RemoveFav_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RemoveFav.Click
            'If you remove the text from the SongName column when adding it to Favorites then add it back to the SongName column
            ListView1.SelectedItems(0).Text = ListView1.SelectedItems(0).SubItems(1).Text
    
            'Now set the Favorites column text to an empty string
            ListView1.SelectedItems(0).SubItems(1).Text = ""
        End Sub
    
        Private Sub cms_Opening(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles cms.Opening
            'Make sure there is a selected item before showing the context menu
            If ListView1.SelectedItems.Count > 0 Then
                'Set the Add and Remove menu items enabled states depending on if the Favorites column has text in it
                AddToFav.Enabled = (ListView1.SelectedItems(0).SubItems(1).Text = "")
                RemoveFav.Enabled = Not (ListView1.SelectedItems(0).SubItems(1).Text = "")
            Else
                e.Cancel = True 'Stop the context menu from showing if no items are selected in the listview
            End If
        End Sub
    End Class



    Tuesday, November 12, 2013 1:41 AM
  • I would appreciate the help. In the picture Song 1 and 4 are seperated by spaces and I want them to be Song 1, then song 4. No BLANK, Song 1,etc...

    For right now, forget the control -- that's the result, not the cause (so to speak).

    In my preliminary class, I have things like Artist/Group, Album, and so on. Do you want to take it to that level? If so, what about other things which meta data might return?

    This can get to be quite an undertaking depending on how far you want to take it.

    Displaying the data shouldn't be confused with getting and working with the data. By that I mean adding new, removing, modifying, and so on. This was my original point way back when we started talking a few nights back.

    ;-)


    Please call me Frank :)

    • Marked as answer by lifewcody Friday, November 15, 2013 11:09 PM
    Wednesday, November 13, 2013 11:39 PM

All replies

  • I have a listview called listview1
    i have 2 column
        -Column 1 names Songs labeled Songs
        -Column 2 named Favorited labeled Favorites
    i have on the listview that it has a Contextmenustrip and when i right click it will add it to the column 2 named Favorites
    I have this code so far:
    ListView1.Items.Add(New ListViewItem({ListView1.SelectedItems(0).Text}))
    It adds a blank item into column 1, and also adds an item into column 2
    I was wondering If I could add code to delete the first item added in the first column
    Any help would be appreciated!

    If you post the code then you'll get more help but before doing that, just looking at the names of the columns, I don't see where the two are related.

    Maybe explain a bit more about your overall goal?


    Please call me Frank :)

    Sunday, November 10, 2013 9:18 PM
  • Hi

    You can remove list view selected item from the list see this sample:

    for (int i = 0; i < listView1.Items.Count; i++ )
    {
        if (listView1.Items[i].Selected)
        {
            listView1.Items[i].Remove();
            i--;
        }
    }

    Sunday, November 10, 2013 9:37 PM
  • Frank,

    I did post code:

    ListView1.Items.Add(New ListViewItem({ListView1.SelectedItems(0).Text}))

    This adds the item to the first column. I then found this code

    Dim str(1) As String
    Dim itm As ListViewItem
    str(1) = ListView1.SelectedItems(0).Text
    itm = New ListViewItem(str)
    ListView1.Items.Add(itm)

    This code adds a blank item to column 0 (Songs) and adds the selected item to column 1 (Favorites)

    Sunday, November 10, 2013 11:03 PM
  • Frank,

    I did post code:

    ListView1.Items.Add(New ListViewItem({ListView1.SelectedItems(0).Text}))

    This adds the item to the first column. I then found this code

    Dim str(1) As String
    Dim itm As ListViewItem
    str(1) = ListView1.SelectedItems(0).Text
    itm = New ListViewItem(str)
    ListView1.Items.Add(itm)

    This code adds a blank item to column 0 (Songs) and adds the selected item to column 1 (Favorites)

    I think you're missing my point. ;-)

    If you have a ListView set to view in detail mode (or a DataGridView, which would be a better choice), then it only makes sense to have *something* in both columns before that row is added.

    If so then have the code check to see that the user has given information for both columns - otherwise the concept of the ListView or DGV doesn't really make much sense.

    Agree?


    Please call me Frank :)

    Sunday, November 10, 2013 11:06 PM
  • Hi

    You can remove list view selected item from the list see this sample:

    for (int i = 0; i < listView1.Items.Count; i++ )
    {
        if (listView1.Items[i].Selected)
        {
            listView1.Items[i].Remove();
            i--;
        }
    }

    I converted the code to vb.net and I got an error about the index. I need code that will delete the first item on the first column
    Sunday, November 10, 2013 11:09 PM
  • There is about 300 entries in the first column and there is none in the seconds column. I want to right click with a ContextMenuStrip and it will say add to favorites. I have that all sort out except the actual adding part. I just need to add the selected item from column 1 to column 2
    Sunday, November 10, 2013 11:12 PM
  • There is about 300 entries in the first column and there is none in the seconds column. I want to right click with a ContextMenuStrip and it will say add to favorites. I have that all sort out except the actual adding part. I just need to add the selected item from column 1 to column 2

    Then that's more like a boolean, right? Sort of like "Is A Favorite" being "Yes" or "No".

    Any way that you go about it, let me suggest that you set up a class with some methods to add, remove, set the "IsFavorite" property, etc., then you populate your ListView (or a DataGridView would be a better choice) from a List(Of Class).

    You can then even, say, have that list saved for them (I'd use XML but a simple delimited text file will work also).

    My point is this though: Use the control (a ListView or a DGV) for "display only", not for working with the actual data.


    Please call me Frank :)

    Sunday, November 10, 2013 11:20 PM
  • No it is not a boolean of Is A Favorite. They are two completely different text files which get loaded into the different columns. 
    Monday, November 11, 2013 12:03 AM
  • No it is not a boolean of Is A Favorite. They are two completely different text files which get loaded into the different columns. 

    I'm not trying to be difficult here, but I'll go back to what I said then:

    If there's no relationship between what's in column "A" and what's in column "B", then having columns makes no logical sense and at the very least will be confusing to your users.

    *****

    Set up some sort of data source, whatever that is, populate that data source however you want, then display the results. Using a control to do both is never a good idea and will always come back to bite you later.

    For what it's worth...


    Please call me Frank :)

    Monday, November 11, 2013 12:08 AM
  • Private Sub RemoveAllBlankEntries(ByVal lv As ListView) If lv IsNot Nothing Then For i As Integer = lv.Items.Count - 1 To 0 Step -1 Dim lvi As ListViewItem = lv.Items(i) If lvi.Text.Trim = "" AndAlso _ lvi.SubItems(1).Text.Trim = "" Then lv.Items.RemoveAt(i) End If Next End If End Sub



    Please call me Frank :)

    Monday, November 11, 2013 12:23 AM
  • There is a relation to column A and column B and I am pretty sure it will be easy for the users to understand as I have presented the ideas to some beta testers and they agree. The code you provided did not work. It removes the complete row
    Monday, November 11, 2013 9:35 PM
  • There is a relation to column A and column B and I am pretty sure it will be easy for the users to understand as I have presented the ideas to some beta testers and they agree. The code you provided did not work. It removes the complete row

    Sorry for the delay...

    The code you provided did not work. It removes the complete row

    I thought that's what you asked for, but be that neither here nor there, it goes back to what I said earlier: Work with the data, not the display of the data.

    If you can provide a screenshot of your concept, then - if you want me to - in the next few days I'll put something together that I think you'll find to be a better way all around.

    If you're not able to post a screenshot then let me know and I'll post a link to my FTP site where you can upload it (or them) and I'll then retrieve them and post them for you.


    Please call me Frank :)

    Tuesday, November 12, 2013 1:20 AM
  • Hi,

     I am not sure but, maybe this will help. I add a few fake song names to the listview and have a contextmenu that has (Add to Favorites) and (Remove From Favorites) . When you right click on an item it tests the text in the 2nd column to set the proper menu item states on the contextmenu. You can add the text from the first column to the 2nd column and then remove it from the 1st column. Then it does the reverse if you remove it from the 2nd column. You can test it quick by creating a new Form project and add 1 ListView to it. Don`t set any properties. Now copy the code below to the forms code. I tried to explain a little in the code so maybe you can understand it better.

    Public Class Form1
        'This creates a new ContextMenuStrip and 2 MenuItems AddToFav and RemoveFav for it.
        Dim WithEvents cms As New ContextMenuStrip
        Dim WithEvents AddToFav As New ToolStripMenuItem With {.Text = "Add To Faforites"}
        Dim WithEvents RemoveFav As New ToolStripMenuItem With {.Text = "Remove From Favorites"}
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'These listview properties can be set on the form [Design] tab instead of here in the code
            ListView1.View = View.Details
            ListView1.FullRowSelect = True
            ListView1.ContextMenuStrip = cms
            ListView1.HeaderStyle = ColumnHeaderStyle.Nonclickable
            ListView1.Columns.Add("Song Name", 100, HorizontalAlignment.Left)
            ListView1.Columns.Add("Favorites", 100, HorizontalAlignment.Left)
    
            cms.Items.Add(AddToFav) 'Adds the ToolStripMenuItems to the ContextMenuStrip
            cms.Items.Add(RemoveFav)
    
            'I just used this loop to fake loading song names into the listview
            For x As Integer = 0 To 5
                Dim lvi As New ListViewItem("Song - " & x.ToString)
                lvi.SubItems.Add("") 'Add an empty string if no text is going in the subitem (Favorites column)
                ListView1.Items.Add(lvi)
            Next
        End Sub
    
        Private Sub AddToFav_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddToFav.Click
            'Set the Favorites column text to the text that is in the SongName column for the selected item
            ListView1.SelectedItems(0).SubItems(1).Text = ListView1.SelectedItems(0).Text
    
            'If you want to remove the text from SongName column when adding it to the Favorites column
            ListView1.SelectedItems(0).Text = ""
        End Sub
    
        Private Sub RemoveFav_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RemoveFav.Click
            'If you remove the text from the SongName column when adding it to Favorites then add it back to the SongName column
            ListView1.SelectedItems(0).Text = ListView1.SelectedItems(0).SubItems(1).Text
    
            'Now set the Favorites column text to an empty string
            ListView1.SelectedItems(0).SubItems(1).Text = ""
        End Sub
    
        Private Sub cms_Opening(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles cms.Opening
            'Make sure there is a selected item before showing the context menu
            If ListView1.SelectedItems.Count > 0 Then
                'Set the Add and Remove menu items enabled states depending on if the Favorites column has text in it
                AddToFav.Enabled = (ListView1.SelectedItems(0).SubItems(1).Text = "")
                RemoveFav.Enabled = Not (ListView1.SelectedItems(0).SubItems(1).Text = "")
            Else
                e.Cancel = True 'Stop the context menu from showing if no items are selected in the listview
            End If
        End Sub
    End Class



    Tuesday, November 12, 2013 1:41 AM
  • Hi,

    I am not sure but, maybe this will help. I add a few fake song names to the listview and have a contextmenu that has (Add to Favorites) and (Remove From Favorites).

    I tend to agree with you which goes back to what I said yesterday: It's related by way of a Boolean being that it either IS or is NOT a favorite.

    It wouldn't make a lot of sense otherwise.

    I hope this solves his problem. :)


    Please call me Frank :)

    Tuesday, November 12, 2013 1:58 AM
  • For what it's worth:

    Option Strict On Option Explicit On Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles MyBase.Load ' Use this area to test with... End Sub End Class ''' <summary> ''' A class encapsulating the members of the user's music information. ''' </summary> ''' <remarks></remarks> Public Class MyMusic Private _filePath As String Private _groupOrArtistName As String Private _albumName As String Private _trackName As String Private _isFavorite As Boolean ''' <summary> ''' You cannot use this constructor to instantiate this class; use the the "AddNew" method instead." ''' </summary> ''' <remarks></remarks> Public Sub New() Throw New Exception("This class cannot be instantiated using this construct.;" & _ vbCrLf & vbCrLf & _ "Use the 'AddNew' method to add a new instance of this class.") End Sub Private Sub New(ByVal filePath As String, _ ByVal groupOrArtist As String, _ ByVal albumName As String, _ ByVal trackName As String, _ ByVal isFavorite As Boolean) If Not My.Computer.FileSystem.FileExists(filePath) Then Throw New ArgumentException("The filepath could not be located.") ElseIf groupOrArtist.Trim = "" Then Throw New ArgumentException("The group or artist cannot be empty.") ElseIf albumName.Trim = "" Then Throw New ArgumentException("The album name cannot be empty.") ElseIf trackName.Trim = "" Then Throw New ArgumentException("The track name cannot be empty.") Else _filePath = filePath _groupOrArtistName = groupOrArtist.Trim _albumName = albumName.Trim _trackName = trackName.Trim _isFavorite = isFavorite End If End Sub ''' <summary> ''' The full file path to this particular song file on the user's computer. ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> Public ReadOnly Property FilePathToSong() As String Get Return _filePath End Get End Property ''' <summary> ''' The group or artist name of this song. ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> Public ReadOnly Property GroupOrArtist() As String Get Return _groupOrArtistName End Get End Property ''' <summary> ''' The name of the album this song is on. ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> Public ReadOnly Property AlbumName() As String Get Return _albumName End Get End Property ''' <summary> ''' The name of the track for this song. ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> Public ReadOnly Property TrackName() As String Get Return _trackName End Get End Property ''' <summary> ''' An indication of whether or not this song is included in the user's favorites. ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> Public Property IsFavorite() As Boolean Get Return _isFavorite End Get Set(ByVal value As Boolean) _isFavorite = value End Set End Property ''' <summary> ''' A method to add a new song to your list of music. ''' </summary> ''' <param name="musicList">Your list of "MyMusic" data.</param> ''' <param name="filePath">The full file path to this song.</param> ''' <param name="groupOrArtist">The group or artist name of this song.</param> ''' <param name="albumName">The name of the album this song is on.</param> ''' <param name="trackName">The name of the track for this song.</param> ''' <param name="isFavorite">OPTIONAL: An indication of whether or not this song is included in the user's favorites.</param> ''' <remarks></remarks> Public Shared Sub AddNew(ByRef musicList As List(Of MyMusic), _ ByVal filePath As String, _ ByVal groupOrArtist As String, _ ByVal albumName As String, _ ByVal trackName As String, _ Optional ByRef isFavorite As Boolean = False) If musicList Is Nothing Then Throw New ArgumentException("The list of your music cannot be null.") Else Try Dim findDuplicate = From mm As MyMusic In musicList Where _ mm.FilePathToSong = filePath OrElse _ (mm.GroupOrArtist.ToLower.Replace(" ", "") = groupOrArtist.ToLower.Replace(" ", "") AndAlso _ mm.AlbumName.ToLower.Replace(" ", "") = albumName.ToLower.Replace(" ", "") AndAlso _ mm.TrackName.ToLower.Replace(" ", "") = trackName.ToLower.Replace(" ", "")) If findDuplicate.Count > 0 Then Throw New ArgumentException("This entry already exists in your list of songs.") Else musicList.Add(New MyMusic(filePath, groupOrArtist, albumName, trackName, isFavorite)) End If Catch ex As Exception Throw End Try End If End Sub ''' <summary> ''' A method to remove an entry from the list of music data. ''' </summary> ''' <param name="musicList">Your list of "MyMusic" data.</param> ''' <param name="filePath">The full file path to this song.</param> ''' <remarks></remarks> Public Shared Sub RemoveEntry(ByRef musicList As List(Of MyMusic), _ ByVal filePath As String) If musicList Is Nothing Then Throw New ArgumentException("The list of your music cannot be null.") Else Dim qry = From mm As MyMusic In musicList Where mm.FilePathToSong = filePath If qry.Count = 1 Then musicList.Remove(qry.First) ElseIf qry.Count = 0 Then Throw New ArgumentException("The filepath specified is not in your list of music.") End If End If End Sub ''' <summary> ''' A method to mofify whether or not this entry is a user's favorite or not. ''' </summary> ''' <param name="musicList">Your list of "MyMusic" data.</param> ''' <param name="filePath">The full file path to this song.</param> ''' <param name="isFavorite">An indication of whether or not this song is included in the user's favorites.</param> ''' <remarks></remarks> Public Shared Sub ModifyIsFavorite(ByRef musicList As List(Of MyMusic), _ ByVal filePath As String, _ ByVal isFavorite As Boolean) If musicList Is Nothing Then Throw New ArgumentException("The list of your music cannot be null.") Else Dim qry = From mm As MyMusic In musicList Where mm.FilePathToSong = filePath If qry.Count = 1 Then qry.First.IsFavorite = isFavorite ElseIf qry.Count = 0 Then Throw New ArgumentException("The filepath specified is not in your list of music.") End If End If End Sub End Class



    Please call me Frank :)

    Tuesday, November 12, 2013 3:07 AM
  • Hi,

     I am not sure but, maybe this will help. I add a few fake song names to the listview and have a contextmenu that has (Add to Favorites) and (Remove From Favorites) . When you right click on an item it tests the text in the 2nd column to set the proper menu item states on the contextmenu. You can add the text from the first column to the 2nd column and then remove it from the 1st column. Then it does the reverse if you remove it from the 2nd column. You can test it quick by creating a new Form project and add 1 ListView to it. Don`t set any properties. Now copy the code below to the forms code. I tried to explain a little in the code so maybe you can understand it better.

    Public Class Form1
        'This creates a new ContextMenuStrip and 2 MenuItems AddToFav and RemoveFav for it.
        Dim WithEvents cms As New ContextMenuStrip
        Dim WithEvents AddToFav As New ToolStripMenuItem With {.Text = "Add To Faforites"}
        Dim WithEvents RemoveFav As New ToolStripMenuItem With {.Text = "Remove From Favorites"}
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'These listview properties can be set on the form [Design] tab instead of here in the code
            ListView1.View = View.Details
            ListView1.FullRowSelect = True
            ListView1.ContextMenuStrip = cms
            ListView1.HeaderStyle = ColumnHeaderStyle.Nonclickable
            ListView1.Columns.Add("Song Name", 100, HorizontalAlignment.Left)
            ListView1.Columns.Add("Favorites", 100, HorizontalAlignment.Left)
    
            cms.Items.Add(AddToFav) 'Adds the ToolStripMenuItems to the ContextMenuStrip
            cms.Items.Add(RemoveFav)
    
            'I just used this loop to fake loading song names into the listview
            For x As Integer = 0 To 5
                Dim lvi As New ListViewItem("Song - " & x.ToString)
                lvi.SubItems.Add("") 'Add an empty string if no text is going in the subitem (Favorites column)
                ListView1.Items.Add(lvi)
            Next
        End Sub
    
        Private Sub AddToFav_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddToFav.Click
            'Set the Favorites column text to the text that is in the SongName column for the selected item
            ListView1.SelectedItems(0).SubItems(1).Text = ListView1.SelectedItems(0).Text
    
            'If you want to remove the text from SongName column when adding it to the Favorites column
            ListView1.SelectedItems(0).Text = ""
        End Sub
    
        Private Sub RemoveFav_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RemoveFav.Click
            'If you remove the text from the SongName column when adding it to Favorites then add it back to the SongName column
            ListView1.SelectedItems(0).Text = ListView1.SelectedItems(0).SubItems(1).Text
    
            'Now set the Favorites column text to an empty string
            ListView1.SelectedItems(0).SubItems(1).Text = ""
        End Sub
    
        Private Sub cms_Opening(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles cms.Opening
            'Make sure there is a selected item before showing the context menu
            If ListView1.SelectedItems.Count > 0 Then
                'Set the Add and Remove menu items enabled states depending on if the Favorites column has text in it
                AddToFav.Enabled = (ListView1.SelectedItems(0).SubItems(1).Text = "")
                RemoveFav.Enabled = Not (ListView1.SelectedItems(0).SubItems(1).Text = "")
            Else
                e.Cancel = True 'Stop the context menu from showing if no items are selected in the listview
            End If
        End Sub
    End Class



    This is about the closest to what I have wanted. To clarify to Frank some more here is what I have

    A text file on the server called favorites.txt

    I use this code to get all the song files on the server

    ' DOWNLOAD SONG TITLES & PUT INTO LISTVIEW
            wc.Credentials = New Net.NetworkCredential("user", "pass")
            Dim oFTP As FtpWebRequest = CType(FtpWebRequest.Create("URL"), FtpWebRequest)
            oFTP.Credentials = New NetworkCredential("user", "pass")
            oFTP.KeepAlive = True
            oFTP.Method = WebRequestMethods.Ftp.ListDirectory
            Dim response As FtpWebResponse = CType(oFTP.GetResponse, FtpWebResponse)
            Dim sr As StreamReader = New StreamReader(response.GetResponseStream)
            Dim str As String = sr.ReadLine
            Dim oList As New List(Of String)
            While str IsNot Nothing
                'Listbox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(str))
                ListView1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(str))
                str = sr.ReadLine
            End While
            sr.Close()
            response.Close()
            oFTP = Nothing
            Return
            wc.Dispose()
            ' // DOWNLOAD SONG TITLES & PUT INTO LISTVIEW

    I then have the 2 columns and I want a copy of whatever is selected on column 1 to go into column 2. I do not want any blank items in the columns

    I just had an idea when I was writing this. I know you have to have a row and that is why it is blank, could I do it so it determines what it will replace on column 1 and then insert that row. So is the song name on row 1 is 115 it will put 115, FavSong. I'm pretty sure that does not make sense


    Tuesday, November 12, 2013 4:40 PM
  • I am not sure what you mean. I think you might be making complete sense, but I am unsure of how that will be done. Having a sub to check whenether the song is a favorite then putting it in the correct column?
    Tuesday, November 12, 2013 4:41 PM
  • I am not sure what you mean. I think you might be making complete sense, but I am unsure of how that will be done. Having a sub to check whenether the song is a favorite then putting it in the correct column?

    Who are you adressing?

    We don't all see this forum the same way - please be explicit.


    Please call me Frank :)

    Tuesday, November 12, 2013 9:31 PM
  • I then have the 2 columns and I want a copy of whatever is selected on column 1 to go into column 2. I do not want any blank items in the columns

    I just had an idea when I was writing this. I know you have to have a row and that is why it is blank, could I do it so it determines what it will replace on column 1 and then insert that row. So is the song name on row 1 is 115 it will put 115, FavSong. I'm pretty sure that does not make sense


     I am not sure but, i think what your saying in the first sentence is when the SongName is added to the Favorites column you don`t want it to be removed from the SongName column. Then if you remove it from the Favorites then it just sets the Favorites column to an empty string. If so then you can just remove a few lines of code in the AddToFav and RemoveFav click event subs from my example code in my last post like this

        Private Sub AddToFav_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddToFav.Click
            'Set the Favorites column text to the text that is in the SongName column for the selected item
            ListView1.SelectedItems(0).SubItems(1).Text = ListView1.SelectedItems(0).Text
        End Sub
    
        Private Sub RemoveFav_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RemoveFav.Click
            'Set the Favorites column text to an empty string
            ListView1.SelectedItems(0).SubItems(1).Text = ""
        End Sub

    And for the second part i believe your idea is to use maybe the row index number and have it add that to the SongName column when it is added to the Favorites something like this

    If so then change the AddToFav and RemoveFav click event subs to something like this

        Private Sub AddToFav_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddToFav.Click
            'Set the Favorites column text to the text that is in the SongName column for the selected item
            ListView1.SelectedItems(0).SubItems(1).Text = ListView1.SelectedItems(0).Text
    
            'Set the SongName column text to the SelectedIndex number
            ListView1.SelectedItems(0).Text = "Favorite - " & (ListView1.SelectedIndices(0) + 1).ToString
        End Sub
    
        Private Sub RemoveFav_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RemoveFav.Click
            'Set the text of the SongName column back to the text in the Favorites column
            ListView1.SelectedItems(0).Text = ListView1.SelectedItems(0).SubItems(1).Text
    
            'Set the Favorites column text back to an empty string
            ListView1.SelectedItems(0).SubItems(1).Text = ""
        End Sub
    

    • Edited by IronRazerz Tuesday, November 12, 2013 11:52 PM Fixed Comments
    Tuesday, November 12, 2013 10:38 PM
  • If that's what he wants then I'll go back to what I said to start with: It makes no sense ...


    Please call me Frank :)

    Wednesday, November 13, 2013 3:54 AM
  • I am not sure what you mean. I think you might be making complete sense, but I am unsure of how that will be done. Having a sub to check whenether the song is a favorite then putting it in the correct column?

    Who are you adressing?

    We don't all see this forum the same way - please be explicit.


    Please call me Frank :)

    I was addressing you. Sorry I need to be more clear
    Wednesday, November 13, 2013 6:16 AM
  • I then have the 2 columns and I want a copy of whatever is selected on column 1 to go into column 2. I do not want any blank items in the columns

    I just had an idea when I was writing this. I know you have to have a row and that is why it is blank, could I do it so it determines what it will replace on column 1 and then insert that row. So is the song name on row 1 is 115 it will put 115, FavSong. I'm pretty sure that does not make sense


     I am not sure but, i think what your saying in the first sentence is when the SongName is added to the Favorites column you don`t want it to be removed from the SongName column. Then if you remove it from the Favorites then it just sets the Favorites column to an empty string. If so then you can just remove a few lines of code in the AddToFav and RemoveFav click event subs from my example code in my last post like this

        Private Sub AddToFav_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddToFav.Click
            'Set the Favorites column text to the text that is in the SongName column for the selected item
            ListView1.SelectedItems(0).SubItems(1).Text = ListView1.SelectedItems(0).Text
        End Sub
    
        Private Sub RemoveFav_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RemoveFav.Click
            'Set the Favorites column text to an empty string
            ListView1.SelectedItems(0).SubItems(1).Text = ""
        End Sub

    And for the second part i believe your idea is to use maybe the row index number and have it add that to the SongName column when it is added to the Favorites something like this

    If so then change the AddToFav and RemoveFav click event subs to something like this

        Private Sub AddToFav_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddToFav.Click
            'Set the Favorites column text to the text that is in the SongName column for the selected item
            ListView1.SelectedItems(0).SubItems(1).Text = ListView1.SelectedItems(0).Text
    
            'Set the SongName column text to the SelectedIndex number
            ListView1.SelectedItems(0).Text = "Favorite - " & (ListView1.SelectedIndices(0) + 1).ToString
        End Sub
    
        Private Sub RemoveFav_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RemoveFav.Click
            'Set the text of the SongName column back to the text in the Favorites column
            ListView1.SelectedItems(0).Text = ListView1.SelectedItems(0).SubItems(1).Text
    
            'Set the Favorites column text back to an empty string
            ListView1.SelectedItems(0).SubItems(1).Text = ""
        End Sub

    The first one was very close. I just need it to be in order. It would go on the next line of the row.

    It does this:

    I would need it to be Song - 1 on the first line and Song - 4 on the second line

    Wednesday, November 13, 2013 6:21 AM
  • If that's what he wants then I'll go back to what I said to start with: It makes no sense ...


    Please call me Frank :)

    A lot of what I do makes no sense, but that's what they call experimenting
    Wednesday, November 13, 2013 6:21 AM
  • If that's what he wants then I'll go back to what I said to start with: It makes no sense ...


    Please call me Frank :)

    A lot of what I do makes no sense, but that's what they call experimenting

    If the second column is an indication that a particular song is a favorite, then it makes sense. The following:

    ...seems to support the notion that they're connected (related). I'd use a checkbox to show it but that's not the only way it can be done.

    In reading what you wrote to IR though, it appears that you want to use two columns simply because they're there - even if the song shown as a favorite happens to correspond with another song (shown in the first column).

    If the latter then to me that makes no sense; it may as well be names of fruit in one column and names of car manufacturers in the second one... there's no relationship but you do get to use both columns I guess.

    Will you clarify what it is that you're trying to do? Do you want to pursue using a class and List(Of Class) or would you prefer me to back out of this thread and leave it to the rest of you now?


    Please call me Frank :)

    Wednesday, November 13, 2013 10:04 PM
  • If that's what he wants then I'll go back to what I said to start with: It makes no sense ...


    Please call me Frank :)

    A lot of what I do makes no sense, but that's what they call experimenting

    If the second column is an indication that a particular song is a favorite, then it makes sense. The following:

    ...seems to support the notion that they're connected (related). I'd use a checkbox to show it but that's not the only way it can be done.

    In reading what you wrote to IR though, it appears that you want to use two columns simply because they're there - even if the song shown as a favorite happens to correspond with another song (shown in the first column).

    If the latter then to me that makes no sense; it may as well be names of fruit in one column and names of car manufacturers in the second one... there's no relationship but you do get to use both columns I guess.

    Will you clarify what it is that you're trying to do? Do you want to pursue using a class and List(Of Class) or would you prefer me to back out of this thread and leave it to the rest of you now?


    Please call me Frank :)

    I would appreciate the help. In the picture Song 1 and 4 are seperated by spaces and I want them to be Song 1, then song 4. No BLANK, Song 1,etc...
    Wednesday, November 13, 2013 11:31 PM
  • I would appreciate the help. In the picture Song 1 and 4 are seperated by spaces and I want them to be Song 1, then song 4. No BLANK, Song 1,etc...

    For right now, forget the control -- that's the result, not the cause (so to speak).

    In my preliminary class, I have things like Artist/Group, Album, and so on. Do you want to take it to that level? If so, what about other things which meta data might return?

    This can get to be quite an undertaking depending on how far you want to take it.

    Displaying the data shouldn't be confused with getting and working with the data. By that I mean adding new, removing, modifying, and so on. This was my original point way back when we started talking a few nights back.

    ;-)


    Please call me Frank :)

    • Marked as answer by lifewcody Friday, November 15, 2013 11:09 PM
    Wednesday, November 13, 2013 11:39 PM
  • I would appreciate the help. In the picture Song 1 and 4 are seperated by spaces and I want them to be Song 1, then song 4. No BLANK, Song 1,etc...

    For right now, forget the control -- that's the result, not the cause (so to speak).

    In my preliminary class, I have things like Artist/Group, Album, and so on. Do you want to take it to that level? If so, what about other things which meta data might return?

    This can get to be quite an undertaking depending on how far you want to take it.

    Displaying the data shouldn't be confused with getting and working with the data. By that I mean adding new, removing, modifying, and so on. This was my original point way back when we started talking a few nights back.

    ;-)


    Please call me Frank :)

    I think I might just do that. That will be much better, since I already know how to do that. Thanks for the help :)
    Friday, November 15, 2013 11:09 PM
  • I would appreciate the help. In the picture Song 1 and 4 are seperated by spaces and I want them to be Song 1, then song 4. No BLANK, Song 1,etc...

    For right now, forget the control -- that's the result, not the cause (so to speak).

    In my preliminary class, I have things like Artist/Group, Album, and so on. Do you want to take it to that level? If so, what about other things which meta data might return?

    This can get to be quite an undertaking depending on how far you want to take it.

    Displaying the data shouldn't be confused with getting and working with the data. By that I mean adding new, removing, modifying, and so on. This was my original point way back when we started talking a few nights back.

    ;-)


    Please call me Frank :)

    I think I might just do that. That will be much better, since I already know how to do that. Thanks for the help :)

    This discussion has revived some ideas in me -- in the next few weeks, I'll be posting something that, in general, might be beneficial to you.

    :)


    Please call me Frank :)

    Saturday, November 16, 2013 1:41 AM