The code I would like to write would look like this:
IEnumerable<SomeModel> items = GetTheItems();
dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = BuildTheDataSource(items);
And the data grid would show the sort glyphs on the headers and allow the user to sort by clicking them.
The most promising lead I’ve had so far was the SortableBindingList proposed by this answer, but that solution (and others) seem to work only for manually created columns.
Update
Well the egg is on my face now! The SortableBindingList does work, but I made a classic blunder:
void Bind(List<Model> items)
{
this.items = new SortableBindingList<Model>(items);
// oops! "items" is a List<T>... what I really wanted was
// "this.items" which is a SortableBindingList<T>
dataGridView1.DataSource = items;
}
If i understand your question. The given example of SortableBindingList
is thus:
so, from the
List<Person>toSortableBindingListthe column is created base in theFields and Propertiesof thePerson.what did you mean from your question?:
but that solution (and others) seem to work only for manually created columns.
Update
Try this one