将匿名类型列表转换为绑定列表

时间:2014-09-26 06:03:29

标签: c# datagridview anonymous-types bindinglist

从我的表中查询列后发生了什么。我做了一个.ToList()并将它用作我的datagridview的dataSource。现在我必须得到函数从datagridview中删除记录,但数据源必须是绑定列表。但我不知道如何将匿名类型列表转换为绑定列表。有人可以向我发光吗?

1 个答案:

答案 0 :(得分:0)

我找到了一种更好的方法将其更改为绑定源。我的目标是删除行...无论如何它是:

public partial class YourForm : Form {

 private BindingSource _source = new BindingSource();

 public YourForm() {
 List<Model> list = _service.GetList();
 _source.DataSource = list;
 _grid.DataSource = _source;
 }
}


Now you can play around with your datasource and the grid will behave itself. Don't forget to call _grid.Refresh() after each change.