有人可以帮我解决GridView错误:
我有一个List<Person>
,我绑定到dataGridView1
dataGridView1.DataSource=list;
然后我这样做,我收到错误
DataTable dt=(DataTable)DataGridView1.DataSource //Error here Please help me!!!
答案 0 :(得分:0)
public class Conn
{
public string Name { get; set; }
public string Address {get; set;}
public Conn(string n, string a)
{
Name = n;
Address = a;
}
}
private static List<Conn> coList = new List<Conn>();
//add stuff to list
BindingSource bs = new BindingSource();
bs.DataSource = coList;
DataGrid.DataSource = bs;
Windows窗体应用程序的工作代码