Question listbox Choose a Specific item ?

TMTakas

Member
Joined
Feb 6, 2013
Messages
15
Programming Experience
Beginner
Hi vbdotnetforums i have a problem with the listbox items.
i need the application to get a specific item from listbox bellow and display it in a msgbox
staranimes.com-_-13605296191.gif

there is so many items in the listbox, but i need just the "http://www.google.com/recaptcha/api/challenge?k=6Lfz ......"
Sorry for the inconvenience
 

Attachments

  • captcha.gif
    captcha.gif
    4.3 KB · Views: 41
thanks, jmcilhinney, the item contains the word "google.com/recaptcha/api"
choose the Element that contains the word "google.com/recaptcha/api" ??
 
Hi,

You can achieve this by using a For loop to iterate through your ListBox items and then checking for a string that contains what you are looking for. You can then set the SelectedItem property of the ListBox to the string you need. Have a look here:-

VB.NET:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
  For Each myString As String In ListBox1.Items
    If myString.Contains("google.com/recaptcha/api") Then
      ListBox1.SelectedItem = myString
      Exit For
    End If
  Next
End Sub

That said, there seem to be many empty strings in your ListBox so you may find it better to do this string check at the point where you populate your ListBox?

Hope that helps.

Cheers,

Ian
 
Back
Top