In addition to
Richard Deeming[
^]'s solution and my comment to His solution...
I'd suggest to use
Dictionary[
^] object when there are rows with duplicate values in
ColA
Dim dgv As DataGridView = Me.DataGridView1
Dim oDict As Dictionary(Of Integer, Integer) = dgv.Rows().Cast(Of DataGridViewRow) _
.OrderByDescending(Function(r) r.Cells("ColA").Value) _
.GroupBy(Function(r) r.Cells("ColA").Value) _
.Select(Function(grp, index) New KeyValuePair(Of Integer, Integer)(grp.Key, index+1)) _
.ToDictionary(Function(kvp) kvp.Key, Function(kvp) kvp.Value)
For Each dgr As DataGridViewRow In dgv.Rows
dgr.Cells(1).Value = oDict(dgr.Cells(0).Value)
Next
Sample output:
80 2
305 1
23 5
43 3
31 4
80 2
305 1
23 5
As you can see, 305 gets 1. rank, 80 - 2. and so on...
Good luck!
[EDIT]
As to the Richard's comment to my answer - small improvement (still using Dictionary object):
Dim oDict As Dictionary(Of Integer, Tuple(Of Integer, Integer)) = dgv.Rows().Cast(Of DataGridViewRow) _
.GroupBy(Function(r) r.Cells("ColA").Value) _
.OrderByDescending(Function(g) g.Key) _
.Select(Function(grp, index) New KeyValuePair(Of Integer, Tuple(Of Integer, Integer))(grp.Key, Tuple.Create(index+1, grp.Count-1))) _
.ToDictionary(Function(kvp) kvp.Key, Function(kvp) kvp.Value)
For Each dgr As DataGridViewRow In dgv.Rows
Dim cumulative As Integer = oDict.TakeWhile(Function(x) x.Key>dgr.Cells(0).Value).Sum(Function(x) x.Value.Item2)
dgr.Cells(1).Value = oDict(dgr.Cells(0).Value).Item1 + cumulative
Next
Result:
80 3
305 1
23 7
43 5
31 6
80 3
305 1
23 7