I am trying to bind a New List(Of KeyValuePair(Of String, Integer)) to a listView
Currently, I have a code off:
Dim TestList As List(Of KeyValuePair(Of String, Integer))
For Each key in GetTPDesc (Which is a list of strings)
TestList.Add(New KeyValuePair(Of String, Integer)(GetTPDesc.ToString, 0))
Next
For Each ArtFailedPair in Table
TestAddIndex = ArtFailedPair.Failed
If TestAddIndex <> 0 Then
TestList(TestAddIndex -1) = New KeyValuePair(Of String, Integer)(TestList(TestAddIndex -1).Key, TestList(TestAddIndex -1).Value +1)
End If
Next
Excuse me for the long block of code, I know the implementation is dirty, and the reason why I used List of KeyValuePair, was due to the need on Index-Based colletion, which Dictionary did not provide me as I thought it would.
And then I try to bind with:
listView.DataSource = TestList
listView.DataBind()
And the ItemTemplate has the Eval(“key”) and Eval(“value”), ofcourse. But it gives me an error, it shows me:
System.Data.Objects.ObjectQuery’1[System.String] instead of the GetTPDesc.
And I also think an incorrent integer value, since it seems to be out of whack.
Thanks.
The GetTPDesc:
Dim GetTPDesc = (From tpProducts In context.TestResultLim
Where tpProducts.Art_no = productNumber
Order By tpProducts.TP_no
Select tpProducts.TP_desc)
The error is in the following line:
you are adding the query to the list instead of the strings.