Get Column name value of the highest row count of list of Datatable


I am trying to get the column name value of the datatable in the list with the highest row count.

This is the sample datatable:

I grouped this by item name and saved to a list of datatable

list = {0,1,2,3}

group (0)
A 12
A 12
A 13
group (1)
B 6
group (2)
C 3
C 3
group (3)
D 13
D 13
D 13

Is there a straightforward way we can get the value of item name of the 3 highest row count like on a datatable variable without for each?
like listDT.Max(Function (x) x.Rows.Count) but instead of int return, it will give me the item name value so I can use it on another logic.


Hello @wonderingnoname ,

Please refer the below post. You can pass the column name and create it as a dictionary or you can build a datatable.

TestDt.AsEnumerable().Select(Function(x) x.Field(Of String)(“YourColumnName”).Trim).ToArray().Where(Function(y) Not String.IsNullOrEmpty(y)).ToArray().Count

1 Like

arrNames = TableList.OrderByDescending(Function (x) x.Rows.Count).Take(3).Select(Function (x) x(0)(“Item Name”).ToString).ToArray

1 Like

Thank you!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.