C#中DataGridView控件绑定数据源有几种方式?

如题所述

第一种:
DataSet ds=new DataSet ();
this.dataGridView1.DataSource=ds.Table[0];

第二种:
DataTable dt=new DataTable();
this.dataGridView1.DataSource=dt;

第三种:
DataSet ds=new DataSet ();
this.dataGridView1.DataSource = ds.Tables["表名"];

第四种:
DataSet ds=new DataSet ();
this.dataGridView1.DataSource = ds;
this.dataGridView1.DataMember = "表名";

第五种:
ArrayList Al = new ArrayList();
this.dataGridView1.DataSource = Al;

第六种:
Dictionary<string, string> dic = new Dictionary<string, string>();
this.dataGridView1.DataSource = dic;

第七种:
DataView dv = new DataView();
this.dataGridView1.DataSource = dv;

第八种:
this.dataGridVi.DataSource = new BindingList<Object>(List<Object>);

就知道这么多了,有些都搞忘了,应该还有很多。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-03-28
最简单的办法是添加一个datasource控件如sqlDataSource1,将其与数据源链接,然后将DataGridView控件的DataSourceID属性与datasource控件绑定。
第2个回答  2013-03-28
我只知道两种
第一种:
dgv.DataSource=source;
dgv.Bind();
第二种:
dgv.Rows.Add();
第3个回答  2013-03-28
常用的有两种,一种是DataGridView.DataSourse ==数据源,
还有一种就是空间绑定 了
相似回答