C#C
C#3y ago
5 replies
Cake

❔ How to add rows in ListView using For loop?

So I'm trying to add multiple rows in ListView using loops.
I write up this
  for(int i = 0; i < AList.Count; i++)
    {
         int n = i + 1;
         string [] row = {n.ToString(), AList[i].ToString() + "×" + BList[i].ToString() + "=", PAList[i].ToString(), CAList[i].ToString() };
                        var listViewItem = new ListViewItem(row);
                        ResultListView.Items.Add(listViewItem);
                    
                }

And I only get 1 row filled seem in the screenshot I took. When I put in string [i] row = , I get the error CS0270 Array size cannot be specified in a variable declaration (try initializing with a 'new' expression).
image.png
Was this page helpful?