4 Replies - 1695 Views - Last Post: 31 August 2011 - 04:13 AM Rate Topic: -----

#1 questionboy123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-August 11

How to delete items from a ListView AND TextFile

Posted 30 August 2011 - 02:52 AM

  Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click
      
        For Each lvItem As ListViewItem In lvPets.SelectedItems
            lvItem.Remove()
        Next

    End Sub





Hi, i was able to delete an item in the listview, but when i refreshed it, it seems that it would not be deleted in the textfile.
Is This A Good Question/Topic? 0
  • +

Replies To: How to delete items from a ListView AND TextFile

#2 kingsonprisonic  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 74
  • Joined: 09-July 09

Re: How to delete items from a ListView AND TextFile

Posted 30 August 2011 - 09:00 AM

Me.ListView1.Clear
Was This Post Helpful? 0
  • +
  • -

#3 Psyguy  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 75
  • View blog
  • Posts: 323
  • Joined: 12-January 11

Re: How to delete items from a ListView AND TextFile

Posted 30 August 2011 - 09:48 AM

In order to update the text file, you are going to have to rewrite the list box items to the file. Basically, what you did was remove the item from the list which, i assume, you read from a text file. So the process will be as follows:

1. read items into list from text file
2. do stuff with list
3. remove unneeded items from list
4. rewrite items to text file
Was This Post Helpful? 0
  • +
  • -

#4 questionboy123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-August 11

Re: How to delete items from a ListView AND TextFile

Posted 31 August 2011 - 01:53 AM

Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click

        If (Form1.ListView1.SelectedItems.Count > 0) Then
            Form1.ListView1.SelectedItems(0).Remove()
        End If

        Dim FileName As String = "C:\Users\Desktop\Listviewsearchedit\listviewsearchedit\bin\Debug\item.txt"
        Dim objWrite As New System.IO.StreamWriter(FileName, False)
        Dim ListCount As Integer
        Dim ListValue As String

        ListCount = 0
        ListValue = Form1.ListView1.GetItem(ListCount)

        Do While ListCount < ListView1.Size
            ListValue = listView1.GetItem(ListValue)
            objWrite.WriteLine(ListValue)
            ListCount = ListCount + 1
        Loop
        objWrite.Close()
    End Sub




As what the last poster said, I wrote this code. Basicially it deletes the ListView Selected Item then it deletes everything on the text file and rewrites it, but it says "GetItem" is not a member of ListView. Is there an alternative?

This post has been edited by questionboy123: 31 August 2011 - 01:58 AM

Was This Post Helpful? 0
  • +
  • -

#5 juunas  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 87
  • Joined: 25-March 09

Re: How to delete items from a ListView AND TextFile

Posted 31 August 2011 - 04:13 AM

Well you could use
For Each item In ListView1.Items
            ListValue = item.ToString()
            objWrite.WriteLine(ListValue)
        Next


instead of the Do-While-loop.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1