如果我理解你的问题。SortableBindingList的给定示例
因此是:
this.dataGridView1.AutoGenerateColumns = false;
this.ColumnId.DataPropertyName = "Id";
this.ColumnFirstName.DataPropertyName = "FirstName";
this.ColumnLastName.DataPropertyName = "LastName";
this.ColumnBirthday.DataPropertyName = "Birthday";
this.ColumnScore.DataPropertyName = "Score";
List<Person> list = new List<Person>();
list.Add(new Person(1, "Tim", "4", new DateTime(1980, 4, 30), 100.1));
list.Add(new Person(2, "Amy", "2", new DateTime(1983, 1, 1), 200.2));
list.Add(new Person(3, "Sarah", "3", new DateTime(1984, 1, 24), 300.3));
list.Add(new Person(4, "Mike", "1", new DateTime(1988, 3, 21), 400.4));
SortableBindingList<Person> persons = new SortableBindingList<Person>(list);
this.dataGridView1.DataSource = persons;
所以,从List<Person>
到SortableBindingList
列是在 的 中创建Fields and Properties
的Person
。
你的问题是什么意思?:
but that solution (and others) seem to work only for manually created columns.
Update
Try this one
dataGridView1.AutoGenerateColumns = true;
IEnumerable<SomeModel> items = GetTheItems();
SortableBindingList<SomeModel> items = new SortableBindingList<SomeModel>(items.ToList());
dataGridView1.DataSource = items;