0

My application fetches information from a website and puts it into one list to be displayed on a form later. On the website this information is grouped in columns of 5 elements, but they all share the same class. I need to display this information on a form in the same way, but the fact that all the elements share the same class forces me to fetch, store and display them all at once, is there a way for me to divide those elements inside the list in groups of 5? Or maybe I have to fetch it in a different way, given the information about those elements being defined by a same class?

Arthad
  • 3
  • 1
  • You can use [GroupBy](https://learn.microsoft.com/en-us/dotnet/csharp/linq/group-query-results) or [Take](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.take?view=netcore-3.1) from LINQ for this purpose – Sergey Anisimov Apr 28 '20 at 09:50
  • You can put the data into a datatable. Then bind the table to the form or website. Binding allows you to take a table and bind the entire table or just some columns of the table. – jdweng Apr 28 '20 at 10:01
  • that's not a bad idea, but another issue is those columns are dynamically created on the website, so at the given time there could be any number of those columns of 5 elements – Arthad Apr 28 '20 at 10:03
  • Here an [mre] will be usefull. It doesn't have to be Html scrapped data. a simple class with a property 'class' could mimic the behavior. Then you have a List of object you want to group by on a class. – xdtTransform Apr 28 '20 at 10:05
  • And split/partition this big list into smaller batch/chunk of fixed size. like => [Split an IEnumerable into fixed-sized chunks (return an IEnumerable> where the inner sequences are of fixed length)](https://stackoverflow.com/q/13709626), [Create batches in linq](https://stackoverflow.com/questions/13731796/), [Split List into Sublists with LINQ](https://stackoverflow.com/questions/419019/), [LINQ Partition List into Lists of 8 members](https://stackoverflow.com/questions/3773403/) – xdtTransform Apr 28 '20 at 10:05

0 Answers0