根据DataSource绑定的对象的不同,可以有一下几种简单的绑定:
// DataSet 、DataTable
// 方式1
DataSet ds=new DataSet ();
this.dataGridView1.DataSource=ds.Table[0];
this.dataGridView1.DataSource = ds.Tables[“表名”];
// 方式2
DataTable dt=new DataTable();
this.dataGridView1.DataSource=dt;
// DataView
DataView dv = new DataView();
this.dataGridView1.DataSource = dv;
// 设置了DataMember
DataSet ds=new DataSet ();
this.dataGridView1.DataSource = ds;
this.dataGridView1.DataMember = “表名”;
// ArrayList
ArrayList Al = new ArrayList();
this.dataGridView1.DataSource = Al;
// dic
Dictionary<string, string> dic = new Dictionary<string, string>();
this.dataGridView1.DataSource = dic;
// List
this.dataGridVi.DataSource = new BindingList(List);
————————————————
版权声明:本文为优快云博主「zgscwxd」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.youkuaiyun.com/zgscwxd/article/details/85373601