How to add data from a List<List<String>> to a list view

i'm having a List<List<String>> MyList and which contains

    { "A1","B1","C1" }
    { "A2","B2","C2" }
    { "A3","B3","C3" }

i need to add this to a ListView control with three columns

so the list view will be like

__Clm1________________Clm2________________Clm3_______________

   A1                  A2                 A2
   B1                  B2                 B3
   C1                  C2                 C3

Is there any way to do this using LINQ

EDIT Here is my solution for this :

ListViewItem[] lItem = MyList.Select(
                                          X => new ListViewItem(X.ToArray())
                                    ).ToArray();
listView1.Items.AddRange(lItem);

But here i need to add an Index.... The List view will be like

___S.No __Clm1________________Clm2________________Clm3_______________
   1      A1                  A2                 A2
   2      B1                  B2                 B3
   3      C1                  C2                 C3

How to add index to the listview?

Answers


Personally I find this a lot cleaner:

var myList = new List<List<string>>()
{
    new List<string>(){ "A1","B1","C1" },
    new List<string>(){ "A2","B2","C2" },
    new List<string>(){ "A3","B3","C3" },
};

listView.BeginUpdate();    
foreach (var row in myList)
{
    var item = new ListViewItem(listView.Items.Count.ToString());
    item.SubItems.AddRange(row);
    listView.Items.Add(item);
}
listView.EndUpdate();

Need Your Help

How To ensure that a variable is used in all the child classes?

java oop inheritance

If i have a interface car that is to be implemented on various classes called BMW , AUDI etc . Now i want all of them to have a string instance color in which their colors should be stored . As the...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.