Results 1 to 3 of 3

Thread: Search bar issues

  1. #1
    FraserM is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    May 2012
    Posts
    2
    Reputation
    0

    Question Search bar issues

    So I am very new to programming and currently working on a school project.
    I added a search bar for a listbox, which removes items if they do not contain a text boxes text, and although it works some of the time, there are certain words that always stay even though they do not contain the search bar text.
    If it helps, there seems to be a pattern on the words which are not deleted, like every third word and so on. I have tried adding more than one if statement, putting i + 1 as well and the pattern changes to every fourth word does not delete.



    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged


    searchBar = TextBox1.Text


    searchResults()


    End Sub


    Private Sub searchResults()


    loadFood()


    For i = 0 To ListBox1.Items.Count - 1


    If ListBox1.Items.Item(i).Contains(searchBar) = True Then


    Else
    ListBox1.Items.Remove(ListBox1.Items.Item(i))


    End If


    Next


    End Sub

  2. #2
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,178
    Reputation
    2368
    Loop the other way, from high index to low index by Step -1.

  3. #3
    FraserM is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    May 2012
    Posts
    2
    Reputation
    0
    Thanks a lot, it works fine now I'll make sure to post my code correctly next time as well.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking