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:
Failed to compare two elements in the array
foreach (List<string> 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);
}
below is the whole function. I originally had a problem with the list but it was solved here populating a list of a list of strings but
The view is set to details
private void ListBooks()
{
lstBooks.Items.Clear();
lstBooks.Columns.Clear();
lstBooks.Visible = true;
List<List<string>> 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<string> 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);
}
}