简体   繁体   English

如何获取特定ListView列的所有行中的值?

[英]How to get the values in all rows of a particular ListView column?

I have a ListView with three columns and I have added 4 records in the ListView . 我有一个包含三列的ListView ,并且在ListView添加了4条记录。 I would like to get the value of the 2 nd column value of each record. 我想获取每个记录的第二列值的值。 How to implement it? 如何执行呢?

var vals = listView1.Items.Cast<ListViewItem>().Select(lvi => lvi.SubItems[1].Text);
// 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);

loop through all the rows and try this. 遍历所有行并尝试执行此操作。

Subitems[columnnumber] will be the column numbr of the required field Subitems [columnnumber]将是必填字段的列编号

lv.Items[i].SubItems[1].Text lv.Items [i] .SubItems [1]。文字

foreach(ListViewItem itm in listView1.Items){ itm.Text/*first column of the particular item*/   itm.SubItem[1].Text/*second column of the particular item*/}

因为foreach循环比for循环访问更快

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM