Hi,
Here is one way you can do this using LINQ to Objects:-
This will create an initial Enumeration of Anonymous Types in the MyTableSummary variable but if you specifically want to convert this to an Array then you can just call the .ToArray method of the Enumeration as demonstrated above.Code:Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Dim myTableSummary = (From myRow As DataGridViewRow In DataGridView1.Rows.Cast(Of DataGridViewRow)() Where Not myRow.IsNewRow Select ID = myRow.Cells(0).Value, _ ItemValue = myRow.Cells(2).Value Group By ID Into G = Group, TotalItems = Count(), ValueOfItems = Sum(CDec(ItemValue))) Dim myArrayOfAnonymousTypes() = myTableSummary.ToArray For Each myElement In myArrayOfAnonymousTypes MsgBox(myElement.ID.ToString & " - " & myElement.TotalItems.ToString & " - " & myElement.ValueOfItems.ToString) Next End Sub
Hope that helps.
Cheers,
Ian




Reply With Quote