By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,097 Members | 1,216 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,097 IT Pros & Developers. It's quick & easy.

Filtering a List Box of words

P: 2
I have:

A textbox (txtLetter)
A button (btnDisplay)
A listbox (lstColors)

On run time, the form automatically creates an Array and gets information from a .txt file.

What I'm trying to do is make it so that the user can input a letter into the textbox, and when btnDisplay is clicked, it would filter the listbox so that only the words with the same starting letter will be displayed.

Can anyone please help me out here?

Thank you.

My code:

Public Class Form1
Dim Colors() As String
Dim strColors As String
Dim upperBound As Integer

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim sr As IO.StreamReader = IO.File.OpenText("a6Colors.txt")
Dim numLines As Integer
numLines = 0

Do While (sr.Peek <> -1)
strColors = sr.ReadLine
numLines += 1
Loop
upperBound = numLines - 1
sr.Close()
End Sub

Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
ReDim Colors(upperBound)
Dim sr As IO.StreamReader = IO.File.OpenText("a6Colors.txt")

For i As Integer = 0 To upperBound
Colors(i) = sr.ReadLine
Next

For i As Integer = 0 To upperBound
lstColors.Items.Add(Colors(i))
Next



End Sub
End Class
Mar 30 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.