Question
Visual Basic- When I type the country name is the text box, it only shows the country with the first letter. If I were to
Visual Basic- When I type the country name is the text box, it only shows the country with the first letter. If I were to type a second letter, the listbox becomes empty. For example, When I type 'a', Angola is present. When I type 'an', there are no countries in the listbox. Any idea as to how I can fix that?
Public Class frmUnitedNations Dim nations() As String = IO.File.ReadAllLines("Nations.txt") Private Sub frmUnitedNations(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load lstOutput.DataSource = nations lstOutput.SelectedItem = Nothing End Sub
Private Sub txtCountry_TextChanged(sender As Object, e As EventArgs) Handles txtCountry.TextChanged Dim query = From nation In nations Where nation.StartsWith(txtCountry.Text.ToUpper) Select nation lstOutput.DataSource = query.ToList() lstOutput.SelectedItem = Nothing End Sub
Private Sub lstOutput_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstOutput.Click txtCountry.Text = lstOutput.SelectedItem lstOutput.DataSource = nations lstOutput.SelectedItem = Nothing End Sub End Class
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started