Reputation: 39
I have a ListView
with three columns and I have added 4 records in the ListView
.
I would like to get the value of the 2nd column value of each record. How to implement it?
Upvotes: 1
Views: 3608
Reputation: 39
foreach(ListViewItem itm in listView1.Items){ itm.Text/*first column of the particular item*/ itm.SubItem[1].Text/*second column of the particular item*/}
since foreach loop can access more fast than for loop
Upvotes: 1
Reputation: 1396
// Convert items to an IEnumerable for LINQ usage
ListViewItem[] items = new ListViewItem[4];
listView.Items.CopyTo(items, 0);
// Use LINQ to get values
IEnumerable<string> secondColumnValues = items.Select(_ => _.SubItems[1].Text);
Upvotes: 2
Reputation: 23786
var vals = listView1.Items.Cast<ListViewItem>().Select(lvi => lvi.SubItems[1].Text);
Upvotes: 5
Reputation: 7349
loop through all the rows and try this.
Subitems[columnnumber] will be the column numbr of the required field
lv.Items[i].SubItems[1].Text
Upvotes: 1