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
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