我想知道如何訪問ListViewDataList的成員ListViewDataItem的數據鍵。如何訪問ListViewDataItem datakeys
我感到奇怪的是,在調試時,可以訪問這裏可以看出
但是當試圖編碼它是不可能期間訪問DataKeyContainer,它也可以是DataKeysContainer這裏
任何意見上看到如何訪問datakeys和值的ListViewDataItem將不勝感激。
我想知道如何訪問ListViewDataList的成員ListViewDataItem的數據鍵。如何訪問ListViewDataItem datakeys
我感到奇怪的是,在調試時,可以訪問這裏可以看出
但是當試圖編碼它是不可能期間訪問DataKeyContainer,它也可以是DataKeysContainer這裏
任何意見上看到如何訪問datakeys和值的ListViewDataItem將不勝感激。
您可以使用後期綁定,即將您的循環變量放在Object
中。這允許您延遲成員驗證,直到運行時訪問成員。它與c#中的動態類似。
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
到ListView
設計時輕鬆自如。
注意:您必須有Option Strict Off
才能正常工作。
在第二個屏幕截圖中,您已經投射到「ListViewItem」 –
@AFriend是正確的。將其更改爲「For Each l as ListViewDataItem」,它應該按照您的要求工作。 – Jaxi
道歉,愚蠢的錯誤,但是,改變爲ListViewDataItem時,問題仍然存在,我仍然無法訪問DataKeys - 查看新的和更新的第二屏幕截圖。 – AF1001