First off, this is purely an experiment and over time will be forgotten but not the (as I see it) why to avoid this method.

Over in another forum a person asked “how to get the sum for column 1 and a sum for column 2 in a DataGridView for the first three rows?” Having sometime to tinker with this my first thought was why not work this out from the DataSource yet the OP did not specify how the DataGridView was loaded and another thought popped into my head (of course it was not the simple way and far from practical), let’s try this with LINQ. The second thought after thinking LINQ is no doubt this is a situation no matter what this is possible yet not practical as conventional methods (pre LINQ) would be better and that working from the data source is best as a DataGridView is a control to view data but get statistics.

After getting close to a viable solution, the IDE started acting up as in slowing down. Throughout the time coding there were failures until I read a post where (and they did not say where they got this from) the developer did a where condition that was “constant” and behold the failures turn into a resolution.

With that said, feel free to download the VS2010 project and try it out. Pasted trying it out I would advise not using code such as this against a DataGridView as this was an exercise only along with using the funky constant in the where condition and lastly unless you have a decent understanding of LINQ it will surely bite you down the road.

Visual Studio 2010 project on SkyDrive.

Sadistic and twisted code
Code:
Public Function GetInformation(ByVal sender As DataGridView, ByVal TakeCount As Int32) As String
    Dim sb As New System.Text.StringBuilder
    Dim Results =
            (
                From row In sender.Rows.Cast(Of DataGridViewRow) _
                .Take(TakeCount) _
                .GroupBy(Function(f) 3 > 0) _
                .Select(Function(group) _
                    New With
                    {
                        .C1Sum = group.Sum(Function(y) CInt(y.Cells(0).Value)),
                        .C2Sum = group.Sum(Function(y) CInt(y.Cells(1).Value)),
                        .C1Max = group.Max(Function(y) CInt(y.Cells(0).Value)),
                        .C2Max = group.Max(Function(y) CInt(y.Cells(1).Value)),
                        .C1Min = group.Min(Function(y) CInt(y.Cells(0).Value)),
                        .C2Min = group.Min(Function(y) CInt(y.Cells(1).Value))
                    }
                )
            ).ToList
    sb.AppendLine("Column 1")
    sb.AppendLine(String.Format("Sum: {0} Min: {1} Max: {2}",
                                Results(0).C1Sum,
                                Results(0).C1Min,
                                Results(0).C1Max
                                )
                            )
    sb.AppendLine("")
    sb.AppendLine("Column 2")
    sb.AppendLine(String.Format("Sum: {0} Min: {1} Max: {2}",
                                Results(0).C2Sum,
                                Results(0).C2Min,
                                Results(0).C2Max
                                )
                            )
    Return sb.ToString
End Function