C # ListView problem adding items

So here is my question: why the code in the first snippet doesn't work when the second one works fine. Also, I have set the view property for the details. I have read all how to add lvi to a list and it fails every time ... also, I do it manually.

So this doesn't work ...

// Iterating through the rows...
for (int x = 0; x < numRows; x++) {
    row = new List<string>();
    // Iterating through the cols...
    for (int y = 0; y < numCols; y++) {
        row.Add(data[y][x]);
    }
    lv.Items.Add(new ListViewItem(row.ToArray()));
}

      

But this will work:

lv.Items.Add(new ListViewItem("foo"));

      

0


a source to share


2 answers


row.Add(data[y][x])

seems suspicious. Why are you accessing data in first column order but iterating in row order? Also, make sure the type row

(you didn't tell us) is actually List<string>

.



+1


a source


ListViewItem looks for String [] try casting row.ToArray () for string [].



0


a source







All Articles