I'm trying to select listbox item if contains a specific string. Here is my code:
string SearchDomain="youdial.in";
for (int i = 0; i < ListBox2.Items.Count; i++)
{
var UrlList = new Uri(ListBox2.Items[i].ToString());
var UrlList = UrlList.Host;
if (UrlList == SearchDomain)
{
ListBox2.SelectedIndex = i;
urllbl.Text = ListBox2.SelectedItem.ToString();
return;
}
}
If ListBox2 have more than 1 matched results than above code select last matched item, but i want to select first matched item. e.g if Query match with 3rd, 7th and 9th item, I want to get the value of 3rd item. Thanks in Advance, sorry for my bad English.

i <= ListBox2.Items.Count. you're lucky it didn't do so before. you're looking fori < ListBox2.Items.Count- Ousmane D.URIand astringlike this -->if (UrlList == SearchDomain). - Ousmane D.