Theo Posted August 14, 2006 Posted August 14, 2006 Hi all, I've got a ListBox, TextBox and a Button. I'm searching the ListBox like in the code below: Private Sub btnZoeken_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnZoeken.Click Dim lbItem As ListItem Dim strFind As String = txtZoeken.Text Dim strFirst As String Dim strRest As String If strFind <> "" Then 'Change the first character into UpperCase and the rest into LowerCase. strFirst = strFind.Substring(0, 1) strRest = strFind.Substring(1) strFind = strFirst.ToUpper() + strRest.ToLower lbItem = lbWerknemers.Items.FindByText(strFind) If IsNothing(lbItem) Then Exit Sub 'Make sure that the found item is selected. lbWerknemers.SelectedValue = lbItem.Value End If End Sub But now it will only work if you give the full text of an item. Isn't it possible to use some sort of wildcards so I can, for example, find the item 'Theo' by only giving 'Th'? Thanks Quote
Administrators PlausiblyDamp Posted August 14, 2006 Administrators Posted August 14, 2006 IIRC the FindByText is case sensitive and only does matching of entire strings. Probably the easiest method is to loop through the items and compare each string one at a time. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.