지연 바인딩을 사용할 수 있습니다. 즉, 루프 변수를 Object
에 입력하십시오. 이렇게하면 런타임에 멤버에 액세스 할 때까지 멤버 유효성 검사를 연기 할 수 있습니다. 그것은 C#에서 dynamic과 비슷합니다. 당신이이 ListView
알고 있기 때문에
For Each itemObject As Object In lstViewModules.Items
' the DataKeysContainer you were looking for
Dim container = CType(itemObject.DataKeysContainer, Control)
' the same l in your loop
Dim l = CType(itemObject, ListViewDataItem)
' from here on, the rest of your loop code should work
Dim key As DataKey = lstViewModules.DataKeys(l.DataItemIndex)
Dim value = key("name")
Next
은 또한 디자인 타임 쉽게 ListView
에 container
캐스팅 할 수있다.
참고 :이 작업을 수행하려면 Option Strict Off
이어야합니다.
출처
2017-05-03 15:45:16
djv
두 번째 스크린 샷에서 'ListViewItem' –
@Afriend로 캐스팅되었습니다. 'For Each l ListViewDataItem'으로 변경하면 필요에 따라 작동합니다. – Jaxi
사과, 어리석은 실수, 그러나 ListViewDataItem으로 변경하면 여전히 문제가 남아 있지만 데이터 키에 액세스 할 수 없습니다. 새롭고 업데이트 된 두 번째 스크린 샷을 참조하십시오. – AF1001