[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 302
  • Last Modified:

Finding a string in a listbox

Hi Experts

In VB.NET i have a listbox (lstData) which has the name and Email address of customers on
each row,using a textbox (txtSearch) i can search the listbox for a customer name and have
it selected but i am unable to figure out the code to search for the customers Email address
(because i think it is not at the begining of each row or index).

Please can you help
0
dizzycat
Asked:
dizzycat
1 Solution
 
ZeonFlashCommented:
What do you have separating the customer name and email address?  Are there a couple spaces, a character (like "/"), or a tab?  If so, you can do a string comparision for the Email address using the .EndsWith method.

'Example, if you have items in your listbox like:  "John Doe / JDoe@email.com"

        Dim strSeparator As String = "/ "
        For i As Integer = 0 To lstData.Items.Count - 1
            If CStr(lstData.Items.Item(i)).EndsWith(strSeparator & txtSearch.Text) Then
                MsgBox("Customer found at index: " & i)
                Exit Sub
            End If
        Next

        MsgBox("Customer not found")

You can use .StartsWith to search only the customer's Names.
0
 
dizzycatAuthor Commented:
Thanks ZeonFlash

I have used lstData.SelectedIndex = (i) together with your code and it works perfectly.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now