Search code examples
c#csvlistlabel

Sorting CSV Data in a Report


I'm trying to print a CSV file with List & Label. I need to sort it by one of the columns, however the sort property is not available. If I use a SQL data source, I can sort it. How can I sort the CSV data? My source is

CsvDataProvider csvDta = new CsvDataProvider(@"C:\temp\myData.csv", true, "Data", ';');

using (ListLabel LL = new ListLabel() { DataSource = csvDta})
{
   LL.Design();
}

Solution

  • A simple way would be to wrap the CSV data in an InMemoryDataProvider. Try this:

    using combit.ListLabel23;
    using combit.ListLabel23.DataProviders;
    
    CsvDataProvider csvDta = new CsvDataProvider(@"C:\temp\myData.csv", true, "Data", ';');
    
    // wrap the table in a queryable data source
    InMemoryDataProvider dataSource = new InMemoryDataProvider();
    dataSource.AddTable(csvDta, "Data");
    
    using (ListLabel LL = new ListLabel() { DataSource = dataSource})
    {
       LL.Design();
    }
    

    This will give you all the glory of sorting and filtering you require.