Domanda

Can someone please tell me what I'm doing wrong....

I am trying to populate an ObjectListView control by looping through a dataset (I don't want to bind it to my dataset). The first row populates but nothing after that.

My code looks like so:

If dsOverdueCalls.Tables.Count > 0 And dsOverdueCalls.Tables(0).Rows.Count > 0 Then
     For x = 0 To (dsOverdueCalls.Tables(0).Rows.Count - 1)
          'Calculate overdue amount
          .....

          Dim lstCalls = New List(Of [Call_Details])() From {New [Call_Details]() With {.Id = tempDT.Rows(x)("id").ToString, .Summary = tempDT.Rows(x)("summary").ToString, .First_Name = tempDT.Rows(x)("first_name").ToString, .Due_At = OverdueStr}}
          lsvOverdueCalls.SetObjects(lstCalls)
     Next
End If

I get no errors but only the first record will populate in my control. Thanks

È stato utile?

Soluzione

You're resetting the ObjectListView in each iteration. So, what you believe is the "first" row is actually the last row. The following code will fix your issue.

If ((dsOverdueCalls.Tables.Count > 0) AndAlso (dsOverdueCalls.Tables(0).Rows.Count > 0)) Then
    Dim lstCalls = New List(Of [Call_Details])
    For x As Integer = 0 To (dsOverdueCalls.Tables(0).Rows.Count - 1)
        lstCalls.Add(New [Call_Details]() With {.Id = tempDT.Rows(x)("id").ToString, .Summary = tempDT.Rows(x)("summary").ToString, .First_Name = tempDT.Rows(x)("first_name").ToString, .Due_At = OverdueStr})
    Next
    lsvOverdueCalls.SetObjects(lstCalls)
End If
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top