So I have a form with a menu bar and a listbox. On the menu bar is the Display option with 3 choices; all, fiction, or nonfiction. The textfile has book titles, author, category (fic"F" or nonfic"N"), stock, price, in that order. When the user clicks on "Display" "all", I want all the titles to display in the listbox. If they click on "Nonfic", just the nonfic titles, and same with "fiction". This is my code so far:
Private Sub menuDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles menuDisplay.Click
Dim books() As String = IO.File.ReadAllLines("Books.txt")
Dim data() As String
Dim allBooksTitle, allNonFicTitle, allFicTitle As String
For i As Integer = 0 To books.Count - 1
data = books(i).Split(","c)
allBooksTitle = data(2)
If data(2).Trim = "N" Then
allNonFicTitle = data(0)
ElseIf data(2).Trim = "F" Then
allFicTitle = data(0)
End If
Next
' show result
If menuDisplayAll.Checked Then
menuDisplayFic.Checked = False
menuDisplayNonFic.Checked = False
lstBox.Items.Clear()
lstBox.Items.Add(allBooksTitle)
ElseIf menuDisplayFic.Checked Then
menuDisplayNonFic.Checked = False
menuDisplayAll.Checked = False
lstBox.Items.Clear()
lstBox.Items.Add(allFicTitle)
ElseIf menuDisplayNonFic.Checked Then
menuDisplayFic.Checked = False
menuDisplayAll.Checked = False
lstBox.Items.Clear()
lstBox.Items.Add(allNonFicTitle)
End If
End Sub
Yet, Every time I debug it, to actually get the titles to show up in the listbox after i check one option, I have to click the values button again. Also, it only shows one book title or both the nonfiction and the fiction, and then for all book it only shows "N". I don't know what I am doing wrong. Any help would be appreciated!
Private Sub menuDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles menuDisplay.Click
Dim books() As String = IO.File.ReadAllLines("Books.txt")
Dim data() As String
Dim allBooksTitle, allNonFicTitle, allFicTitle As String
For i As Integer = 0 To books.Count - 1
data = books(i).Split(","c)
allBooksTitle = data(2)
If data(2).Trim = "N" Then
allNonFicTitle = data(0)
ElseIf data(2).Trim = "F" Then
allFicTitle = data(0)
End If
Next
' show result
If menuDisplayAll.Checked Then
menuDisplayFic.Checked = False
menuDisplayNonFic.Checked = False
lstBox.Items.Clear()
lstBox.Items.Add(allBooksTitle)
ElseIf menuDisplayFic.Checked Then
menuDisplayNonFic.Checked = False
menuDisplayAll.Checked = False
lstBox.Items.Clear()
lstBox.Items.Add(allFicTitle)
ElseIf menuDisplayNonFic.Checked Then
menuDisplayFic.Checked = False
menuDisplayAll.Checked = False
lstBox.Items.Clear()
lstBox.Items.Add(allNonFicTitle)
End If
End Sub
Yet, Every time I debug it, to actually get the titles to show up in the listbox after i check one option, I have to click the values button again. Also, it only shows one book title or both the nonfiction and the fiction, and then for all book it only shows "N". I don't know what I am doing wrong. Any help would be appreciated!