2 Replies - 9728 Views - Last Post: 14 February 2012 - 12:48 PM Rate Topic: -----

#1 jessicalegner   User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 66
  • Joined: 05-June 09

Deleting Items from ListBox

Posted 13 February 2012 - 09:29 PM

I am having an issue with deleting items from a listbox. I am not selecting and then deleting, I am deleting items if they match a string in a file. I understand that I cannot use a for each loop for this because of the enumeration. I tried this for loop and still cannot get it right. Any help would be greatly appreciated.

Sub DELETE(ByVal Course As Course, ByVal DeleteCourse As Course, ByVal lstSchedule As ListBox)
        Dim deletefile As IO.StreamReader = IO.File.OpenText("DeleteCourses.txt")
        Do While deletefile.Peek <> -1
            Dim addline() As String = deletefile.ReadLine.Split(","c)
            DeleteCourse.Title = addline(0) 'course title to be deleted
            For i As Integer = 0 To lstSchedule.Items.Count - 1
                Dim scheduleLine As String = lstSchedule.Items(i).ToString()
                Dim schedline() As String = scheduleLine.Split(","c)
                Course.Title = schedline(0) ' course title in the listbox
                If (DeleteCourse.Title = Course.Title) Then 'if the titles match
                End If
    End Sub

Is This A Good Question/Topic? 0
  • +

Replies To: Deleting Items from ListBox

#2 maj3091   User is offline

  • D.I.C Lover
  • member icon

Reputation: 330
  • View blog
  • Posts: 1,998
  • Joined: 26-March 09

Re: Deleting Items from ListBox

Posted 14 February 2012 - 02:44 AM

You might want to look at the line below:


I think the scheduleLine, should be your loop integer i.


I'm not sure if that helps as this is VB.Net, something that I'm not that familiar with, so you may want to ask a mod to move it to the right forum if you don't get any joy.
Was This Post Helpful? 0
  • +
  • -

#3 Rhymer   User is offline

  • D.I.C Regular

Reputation: 23
  • View blog
  • Posts: 282
  • Joined: 21-April 09

Re: Deleting Items from ListBox

Posted 14 February 2012 - 12:48 PM

It may be easier to create an array for the items. If you delete just make the array element nothing ie: "" then clear the listbox and repopulate it from what's left in the the array.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1