Remove group from list of datatable and save it on another list

Hello!

I would like to remove 2 of the datatable on the list and move it to another list.

Example: I have this group saved in listDTgrp
image
**Uploaded correct sample

I would like to remove grp1 and grp3 and move it on another list. Is there a way to do it without for each?

Thanks,

@wonderingnoname , Do you want to move the grp1 and grp3 Datatable as Highlighted in the Screenshot to another Sheet in Excel ?

Also, Do we have the Data in Excel or Do we have it in variable ?

We would also require to know what is the Type of this variable.

the main file is from excel. I used groupBy to group them by itemname (a,b,c,d) and save it on listDT {list}

I have a condition that I need to get the 2 group with highest datarow and remove them on the original list of datatable. Save that datatable with the remaining 2 and create another list of datatable to save the group we removed.

so in the final solution the groupings are the following:

listDT {list} = {grp2, grp4}
listDTnew {list} + {grp1, grp3}

I hope this makes sense

@wonderingnoname , Is the Condition based on the Number of rows present for the Group ?

If the row count are the same like in the Screenshot you have provided, what should be done ?

Oh I am sorry. That was my bad. this is the correct sample:
image

lets assume following:

TableList | List(Of DataTable) - each grp is a datatable and contained within the list

TableList.OrderByDescending(Function (x) x.Rows.Count).take(2).ToList

1 Like

@wonderingnoname ,

Adding to What @ppr has mentioned, if you want to remove those Two Grps from the List then you can use the Below Expression and assign it back to the same variable:

TableList = TableList.OrderByDescending(Function (x) x.Rows.Count).Skip(2).ToList
1 Like

This is what I was looking for! Thank you @ppr and @supermanPunch

1 Like

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