簡體   English   中英

如何在C#中通過索引從子項獲取文本值

[英]How to get the text value from a subitem by index in C#

我設法從列表視圖中列的第一項中獲取索引,但是從同一行中,我想使用索引號從第二列中獲取文本值。

 // 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索引相同的Column '的文本值。

這應該可能嗎?

嘗試這個 :

此處的索引被分配為字符串。將其設為整數,則只有secondValue會給出任何輸出。 var index = listview1.Items.IndexOf(item);

ListView類中沒有名為SubItems方法。 如果需要下一項,則需要在索引上加上1的值。

string secondValue = listview1.Items(index+1).ToString();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM