0

我已经设法从列表视图中列中的第一项获取索引,但是从同一行我想通过使用索引号从第二列获取文本值。

 // 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。所以现在有了这些索引值,我想获得与Columnname 具有相同索引的 'Information'的文本值Column

这应该是可能的?

4

1 回答 1

1

尝试这个 :

在这里,索引被分配为一个字符串。将其设置为一个整数,然后只会secondValue给出任何输出。var index = listview1.Items.IndexOf(item);

SubItemsListView 类中没有命名方法。如果您想要下一项,则意味着您需要将 1 值添加到 index 。

string secondValue = listview1.Items(index+1).ToString();
于 2016-08-16T01:15:52.757 回答