Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27031

converting List to Array

$
0
0
Hello guys!

I wanted to create two lists and then convert them to arrays, with the data from this table:

idSuplier Item Price
1 Item A 10.00
1 Item B 20.00
1 Item C 30.00
2 Item A 20.00
2 Item B 30.00
2 Item C 40.00
3 Item A 30.00
3 Item B 40.00
3 Item C 50.00

Ok! the desired result would be: (1, 60.00); (2, 90.00) and (3, 120.00)

So, I've tried the following code to create my array, but I haven't any results!

Code:

Private Sub List()
       

        Dim idSupplier As List(Of Integer) = New List(Of Integer)
        Dim sumSupplier As List(Of Decimal) = New List(Of Decimal)
        Dim value As Decimal

        For i = 1 To j
            For Each col As DataGridViewRow In dgItems.Rows
                If col.Cells(0).Value = i Then
                    value = value + CDec(col.Cells(2).Value)
                    sumSupplier.Add(value)
                    idSupplier.Add(i)



                End If


            Next
           
        Next i
        Dim idSupplierArray() = idSupplier.ToArray()
        Dim sumSupplierArray() = sumSupplier.ToArray()

       
        Console.ReadLine()

    End Sub

Sorry if It seems so dumb, but its what I am...any hint?

Viewing all articles
Browse latest Browse all 27031

Trending Articles