I have managed to get the index from the very first item in the column in my listview, but from that same line I want to get the text value from the second Column by using the index number.
// 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?
}
I really tried everything, but it doesn't seem to work.
EDIT:
There should be a method with SubItem
cause it looks like this in visual:
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
What I know is that the index of Harry = 0 and the index of Jack = 3. So now with those index values I want to obtain the text value of the Column
'Information' that has the same index as the name Column
.
This should be possible?
Try this :
Here the index is assigned as a string .Make it as an integer then only secondValue
will give any output . var index = listview1.Items.IndexOf(item);
There is no method named SubItems
in ListView class . If you want the next item means you need to plus 1 value to the index .
string secondValue = listview1.Items(index+1).ToString();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.