I have a .NET class I’d like to show in a DataGridView, and the default databinding – setting the DGV’s DataSource to the object – produces 90% of my requirements (i.e. it’s outputting the public properties correctly and I can add sorting easily).
However, one of the properties I need to bind is a List which contains data which needs to be in separate columns after the other databound items. I’m stuck on how best to implement this.
My class looks something like this:
public class BookDetails
{
public string Title { get; set; }
public int TotalRating { get; set; }
public int Occurrence { get; set; }
public List<int> Rating { get; set; }
}
Ideally, I’d be able to expand that Rating property into a number of numeric columns to give an output like this at runtime:
Title | Total Rating | Occurrence | R1 | R2 | R3 … RN
It would also be useful to have Total Rating be calculated as the sum of all the individual ratings, but I’m updating that manually at the moment without issue.
Like this?