title: Search in ListView c#
body: <p>I've wrote a method to search thru ListView for a given string and mark the ones that are found with <code>Color</code>. It works fine however with lots of information on screen and scrollable ListView it's sometimes hard to find what user is looking for. </p>
  
  <p>Normally I do create <code>special</code> searches by modifying method and SQL query <code>WHERE</code> clause but it's always a pain and requires more work/code for each ListView/Data. </p>
  
  <p>I would like to have some generalized search that would work for all kind of searches in ListView just like one I have now but with ability to hide (rows) what's not needed and show only necessary rows. Of course if one changes it's mind it has to bring back the old rows back. </p>
  
  <p>I guess the biggest problem for me is how to store all the columns and data without over complicating knowing that it can be 3 to 20+ columns and multiple rows.</p>
  
  <pre><code>public static void wyszukajNazweListView(ListView varListView, string varWyszukaj) {
          if (varWyszukaj != "") {
              foreach (ListViewItem comp in varListView.Items) {
                  comp.UseItemStyleForSubItems = false;
                  foreach (ListViewItem.ListViewSubItem drv in comp.SubItems) {
                      string textToAdd2 = drv.Text;
                      if (textToAdd2.Length &gt;= 1) {
                          if (textToAdd2.ToLower().Contains(varWyszukaj.ToLower())) {
                              drv.BackColor = Color.DarkOrange;
                          } else {
                              drv.BackColor = Color.White;
                          }
                      }
                  }
                  bool varColor = false;
                  foreach (ListViewItem.ListViewSubItem drv in comp.SubItems) {
                      if (drv.BackColor == Color.DarkOrange) {
                          varColor = true;
                          break;
                      }
                  }
                  if (varListView.SmallImageList != null) {
                      if (varColor) {
                          comp.ImageIndex = 2;
                      } else {
                          comp.ImageIndex = -1;
                      }
                  }
              }
          } else {
              foreach (ListViewItem comp in varListView.Items) {
                  comp.UseItemStyleForSubItems = false;
                  comp.BackColor = Color.White;
                  foreach (ListViewItem.ListViewSubItem drv in comp.SubItems) {
                      drv.BackColor = Color.White;
                      comp.ImageIndex = -1;
                  }
              }
          }
      }
  </code></pre>