[英]C# How to get the subitem on a listview to stay on the same line as the item?
[英]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.