Can FindByText use wildcards?

Theo

Newcomer
Joined
Aug 11, 2006
Messages
14
Location
Netherlands
Hi all,

I've got a ListBox, TextBox and a Button. I'm searching the ListBox like in the code below:

Code:
    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
 
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.
 
Back
Top