Search code examples
c#exceldatareader

Ignore specific columns from loading into the DataSet using ExcelDataReader?


I'm using ExcelDataReader to load the data into an DataSet, which will be eventually be loaded into an DataGrid in WPF. I have specific columns with headers as SLNO and FY which I don't want to include. How can I ignore those columns using FilterColumn mentioned here?


Solution

  • You could handle the AutoGeneratingColumn event:

    private void DataGrid_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
    {
        e.Cancel = e.PropertyName == "SLNO" || e.PropertyName == "FY";
    }