Textbox Listbox

G

Guest

Hi,
I have textbox and listbox on my form . Listbox has data. When user key in
the data in textbox closest item in listbox should get selected. (like
keypress in listbox) .How to achieve this
Thanks in advance
Sudheendra
 
S

Stoitcho Goutsev \(100\)

Sudhee,

You should use ListBox's FindString or FindStringExact methodos. In your
case I believe you need the FindString method.
 
G

Guest

Hi,
Thanks, This works only problem I am facing is when I type in textbox first
letter ,the focus will always go to the first item in the list box ,only
after I enter second letter it will search for the first letter for example
I have
Apple
Orange
Guava
Banana

If I type O in text box it will first focus Apple and on keying r it will
focus orange. Always goes to the first item. is there anyway to overcome this.
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

Me.ListBox1.SelectedIndex = Me.ListBox1.FindString(Me.TextBox1.Text)
End Sub
Thanks
Sudhee
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top