DataTable : Is there a way to get the result of 'After'?

@sumouse
in general we can handle by grouping the data

here we also have the choice on Non-LINQ, LINQ approaches

In addition to above mentioned suggestions find below a LINQ Approach:

  • (DataTable Reconstruction, Indexed Select, Tuple, Origin Position Ordering…)

With some modified test case we also showcasing the correct group numbering and origin position keeping)

grafik
grafik

(From d In dtData.AsEnumerable
Group d By k=d("Name").toString.Trim Into grp=Group
From t In grp.Select(Function (x, i) Tuple.Create(x,i+1))
Let ra = t.Item1.ItemArray.Take(t.Item1.ItemArray.Length - 1).Append(t.Item2).ToArray
Order By dtData.Rows.IndexOf(t.Item1)
Select r = dtResult.Rows.Add(ra)).CopyToDataTable