Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleLet the user type a prefix string to select an item in a ListBox in VB .NET
KeywordsListBox, select item
CategoriesControls, VB.NET
 
My book Ready-to-Run Visual Basic Code Library shows how to let the user type in a TextBox and have the program select the first ListBox item that matches the text. That example uses an API function to tell the ListBox to select the matching item.

This example does something similar in VB .NET. The features of many use API functions have been incorporated into VB .NET controls and this is the case here. The VB .NET ListBox control has a FindString method that returns the index of the first item matching some text. The program uses this value to set the control's SelectedIndex property.

 
Private Sub txtSelection_TextChanged(ByVal sender As _
    System.Object, ByVal e As System.EventArgs) Handles _
    txtSelection.TextChanged
    lstWords.SelectedIndex = _
        lstWords.FindString(txtSelection.Text)
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated