このコードはそれを行います。私は巨大なデータテーブルを試していないので、どれくらいの時間がかかるかを確認する必要があります:
Private Function FindMaxDataTableValue(ByRef dt As DataTable) As Integer
Dim currentValue As Integer, maxValue As Integer
Dim dv As DataView = dt.DefaultView
For c As Integer = 0 To dt.Columns.Count - 1
dv.Sort = dt.Columns(c).ColumnName + " DESC"
currentValue = CInt(dv(0).Item(c))
If currentValue > maxValue Then maxValue = currentValue
Next
Return maxValue
End Function
各列を順番にソートし、最初の値が現在の最大値よりも大きい場合は更新します。
追加のクレジットとしてこれを行うことができますが、次IndexOfを見つけるために を実行するとパフォーマンスが低下する可能性がありますrowIndex。
Private Function FindMaxDataTableValue(ByRef dt As DataTable) As Integer
Dim currentValue As Integer, maxValue As Integer
Dim rowIndex As Integer, colIndex As Integer
Dim dv As DataView = dt.DefaultView
For c As Integer = 0 To dt.Columns.Count - 1
dv.Sort = dt.Columns(c).ColumnName + " DESC"
currentValue = CInt(dv(0).Item(c))
If currentValue > maxValue Then
rowIndex = dt.Rows.IndexOf(dv(0).Row)
colIndex = c
maxValue = currentValue
End If
Next
Debug.WriteLine("Max value found at Col:" + colIndex.ToString + " Row:" + rowIndex.ToString)
Return maxValue
End Function