2016-08-15 2 views
0

내 listview의 열에있는 첫 번째 항목에서 색인을 가져 왔지만 같은 줄에서 두 번째 항목의 텍스트 값을 가져 오려고합니다. 인덱스 번호를 사용하여 열.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 

내가 알고있는 것은 그 해리 = 0의 인덱스와 잭의 인덱스 = 3 이제 색인 값을 사용하여 Column과 동일한 색인을 가진 Column '정보'의 텍스트 값을 얻고 싶습니다.

가능해야합니까?

+0

'listview1.Items (index + 1)'이라고하면 어떻게됩니까? – Rahul

+0

'index'는 숫자 값입니까? ToString()을 사용하지 않아도됩니다. –

+0

또한 MSDN 도움말 문서를 탐색하는 방법을 배우는 것이 좋습니다. 각 클래스에서 사용할 수있는 메소드와 사용 방법에 대한 많은 정보를 제공합니다. –

답변

1

이 시도 :

여기

인덱스가 만 secondValue는 출력을 줄 것이다 정수로 .Make 문자열로 지정됩니다. var index = listview1.Items.IndexOf (item);

ListView 클래스에 SubItems이라는 메서드가 없습니다. 다음 항목을 원할 경우 인덱스에 1을 더한 값이 필요합니다.

string secondValue = listview1.Items(index+1).ToString(); 
관련 문제