title: Search listbox for item containing a string
body: <p><strong>Background</strong>: I am building a database application to store information about my massive movie collection. The listbox contains hundreds of items so I decided to implement a search feature which would highlight all items that contain a particular string. Sometimes it's hard to remember an entire movie title so I thought this would come in handy.</p>
  
  <p>I found this useful code on the Microsoft site that highlights all items in a listbox that contain a particular string. How can I modify it to search through each string entirely? </p>
  
  <p>Currently the code only searches for items that <strong>start</strong> with the search string, instead of seeing if it contains the search string anywhere else. I came across a listbox.items.contains() kind of method on Google, although I have no idea how to convert my code for it. </p>
  
  <p><a href="http://forums.asp.net/t/1094277.aspx/1" rel="nofollow">http://forums.asp.net/t/1094277.aspx/1</a></p>
  
  <pre><code>private void FindAllOfMyString(string searchString)
  {
     // Set the SelectionMode property of the ListBox to select multiple items.
     listBox1.SelectionMode = SelectionMode.MultiExtended;
  
     // Set our intial index variable to -1.
     int x =-1;
     // If the search string is empty exit.
     if (searchString.Length != 0)
     {
        // Loop through and find each item that matches the search string.
        do
        {
           // Retrieve the item based on the previous index found. Starts with -1 which searches start.
           x = listBox1.FindString(searchString, x);
           // If no item is found that matches exit.
           if (x != -1)
           {
              // Since the FindString loops infinitely, determine if we found first item again and exit.
              if (listBox1.SelectedIndices.Count &gt; 0)
              {
                 if(x == listBox1.SelectedIndices[0])
                    return;
              }
              // Select the item in the ListBox once it is found.
              listBox1.SetSelected(x,true);
           }
  
        }while(x != -1);
     }
  }
  </code></pre>