Question select data in Listbox through Textbox TextChange value?

JhunBB

Member
Joined
Jul 19, 2012
Messages
11
Programming Experience
Beginner
I am trying to create a webform that List down all the Customers Fullname, and through textbox input i should find name in listbox.

ListBox has a DataSource, and DisplayMember
----------------------
DataSource: BiddersFullnameQuery
DisplayMember: Fullname

----------------------
this is code:

Private Sub txtSearchBidder_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearchBidder.TextChanged
With BiddersList
For x As Integer = 0 To .Items.Count - 1
If .Items(x).ToString.ToLower = txtSearchBidder.Text.ToString.ToLower Then
.SelectedItem = txtSearchBidder.Text
End If
Exit For
Next
End With
Exit Sub
End Sub

Thank you in advance for your help.
 
Don't use this event. It will search every time a new character is typed and you're doing a specific search. Put in a submit button or link to the Enter key.

Other than that please be specific about what you need help with.
 
Don't use this event. It will search every time a new character is typed and you're doing a specific search. Put in a submit button
That is only true if TextBox.AutoPostBack=True, by default it is not. Submit buttons is common in ASP.Net environment, but there may exist options using client script or AJAX also.
 
There is no harm in doing this over a local dataset, as long as you don't query a database everytime a key is pressed... We use this mechanism in a custom grid control, although it's not a full search, the query matches to " LIKE @SearchWord + '%' ". Searching for "store" matches "storeroom" but not "backstore".

I wouldn't use a For...Next loop though, look into using Linq: Introduction to LINQ in Visual Basic
 
Yeah your right, specific search in listbox should perform every time i enter a character in the textbox. Is there any way to perform this event?

thanks Dunfiddlin.
 
guys, thank you so much for your reply.

i already solve my problem.

this is the script i made.

With BiddersList
.DataSource = Me.AIA052004_beDataSet.BiddersFullNameQry.Select("Fullname like '%" & Me.txtSearchBidder.Text & "%'")
End With
 
Back
Top