I have a model like this:
public class Instrument
{
public string Id { get; set; }
public string Name { get; set; }
// About 100 other properties
}
And I retrieve Instrument instances from an Entity Framework EDM.
Now what I would like to do is to be able to make a custom mapping to bind this dataset to a Excel ListObject. By default, ListObject will display every column in the Excel worksheet but I only want to show some properties and in a particular order.
ExcelTools.ListObject instrumentsTable = this.Controls.AddListObject(tableStart, tableName);
instrumentsTable.DataSource = myEDM.Instruments;
// Custom mapping code...
I tried to use the SetDataBinding method but it was throwing a data binding exception.
Do anybody can help me achieving that?
Thanks.
I don’t know if this is helpful, but I created a test project doing this. The test project runs without problems.
First, I declare a test class:
I have a function getInstruments, that returns a List.
Then I bind this to a sheet using this code:
This displays a sheet with 4 instruments showing Name and Property1 in columns A and B.
I also tried this using Entity framework, connecting the sheet to one of my databases and didn’t run into any problems with that either.
If you are still having problems, please give more information about the exception you get when using SetDataBinding.