+92 332 4229 857 99ProjectIdeas@Gmail.com

Searching In ListBox Through Loop (C#.net)



The following code shows you how to searching in listbox and select that searched item.






Through for Loop:

for (int i = 0; i < ListBox1.Items.Count; i++)
{
    if (TextBox1.Text.Equals(ListBox1.Items[i].ToString()))
    {
        ListBox1.SetSelected(i, true); // Selecting that item which is found
    }
}

Through foreach Loop:

int i = 0;
                   
foreach (object obj in ListBox1.Items)
{
   if (obj.ToString().Equals(TextBox1.Text))
   {
       ListBox1.SetSelected(i, true);
   }
                       
  i++;
}
                                 

0 comments: