title: adding items to listview in loop
body: <p>I have a problem with listview. I am not sure how to use a loop to fill the items. The following code works for the first row and I think that I need to increment the row but I'm not sure how. When the list contains more than 1 entry I get the error message:</p>
  
  <blockquote>
    <p>Failed to compare two elements in the array</p>
  </blockquote>
  
  <pre><code>foreach (List&lt;string&gt; l in list)
  {
      ListViewItem item = new ListViewItem(l[0]);
      item.SubItems.Add(l[1]);
      item.SubItems.Add(l[2]);
      item.SubItems.Add(l[3]);
      item.SubItems.Add(l[4]);
      lstBooks.Items.Add(item);
  }
  </code></pre>
  
  <p>below is the whole function. I originally had a problem with the list but it was solved here <a href="https://stackoverflow.com/questions/5440684/populating-a-list-of-a-list-of-strings-but">populating a list of a list of strings but</a></p>
  
  <p>The view is set to details</p>
  
  <pre><code>    private void ListBooks()
      {
          lstBooks.Items.Clear();
          lstBooks.Columns.Clear();
          lstBooks.Visible = true;
  
          List&lt;List&lt;string&gt;&gt; list = db.ListDetailsByGenre();
          lstBooks.Columns.Add("Title", 120);
          lstBooks.Columns.Add("Author", 120);
          lstBooks.Columns.Add("Library", 120);
          lstBooks.Columns.Add("Genre", 120);
  
  
  
       foreach (List&lt;string&gt; l in list)
  
              ListViewItem item = new ListViewItem(l[0]);
              item.SubItems.Add(l[1]);
              item.SubItems.Add(l[2]);
              item.SubItems.Add(l[3]);
              item.SubItems.Add(l[4]);
              lstBooks.Items.Add(item);
  
          }
  
      }
  </code></pre>