【发布时间】:2016-12-22 05:19:09
【问题描述】:
我已经设法从列表视图中列中的第一项获取索引,但在同一行中,我想使用索引号从第二列获取文本值。
// Gets the item from the listview
var item = listview1.FindItemWithText(textbox4.Text);
if (item != null)
{
// Gets the index number from that item
var index = listview1.Items.IndexOf(item).ToString();
string secondValue = listview1.Items(index).SubItems(1).Text);
// secondVlaue should have the subitems txt value?
}
我真的尝试了所有方法,但它似乎不起作用。
编辑:
应该有一个带有SubItem 的方法,因为它在视觉上看起来像这样:
index Name: Information:
0 Harry Harry hasn't been online for 7 days
1 Jason jason hasn't been online for 5 days
2 Sarah Sarah hasn't been online for 2 days
3 Jack Online
我所知道的是 Harry 的索引 = 0 和 Jack 的索引 = 3。所以现在有了这些索引值,我想获得与姓名Column。
这应该可以吗?
【问题讨论】:
-
如果你说
listview1.Items(index + 1)呢? -
index是数值吗?你可能不需要ToString()。 -
我还建议您学习如何浏览 MSDN 帮助文档。它提供了大量关于每个类可用的方法以及如何使用它们的信息。
标签: c# listview indexing indexof subitem