Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

how to bind the listbox and textbox

Hi,

I am working on a windows application. In the windows form, I have a listbox, a textbox, a button and a data grid.
This listbox lists store numbers. Is there anyway to bind the textbox and the listbox together, so that when user type in any number, it will highlight the closest store number in the listbox.
By doing so, the user can easily find a store and select the store. After user click the GO button, the datagrid will display the data.

Here is the code of listbox, so how to bind the listbox and textbox?

Please help! Thank you in advance.
----------
Private Sub Operations_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim daStoreNum As SqlDataAdapter
Dim dsStoreNum As New DataSet
conDWDb.Open()
daStoreNum = New SqlDataAdapter("SELECT DISTINCT Store_Num FROM Store_Table order by store_num", conDWDb)
dsStoreNum = New DataSet("Store_Table")
daStoreNum.Fill(dsStoreNum, "StoreTable")
lstStoreNum.DataSource = dsStoreNum.Tables("StoreTable")
lstStoreNum.DisplayMember = "Store_Num"
lstStoreNum.ValueMember = "Store_Num"
End Sub
[1241 byte] By [JenHu] at [2007-11-11 8:51:23]
# 1 Re: how to bind the listbox and textbox
When you say "select the closest store number", you need to add logic (what is the closest number) and can therefore handle the textbox textchanged event and select the correct (closest) listview item.

Since the textbox may or may not have a match (what if the user enters "abc"), you can handle all valid and invalid entries in the textchanged event.
darren at 2007-11-11 21:46:53 >