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?
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With