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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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>);

就知道这么多了,有些都搞忘了,应该还有很多。
参考技术A 最简单的办法是添加一个datasource控件如sqlDataSource1,将其与数据源链接,然后将DataGridView控件的DataSourceID属性与datasource控件绑定。 参考技术B 我只知道两种
第一种:
dgv.DataSource=source;
dgv.Bind();
第二种:
dgv.Rows.Add();
参考技术C 常用的有两种,一种是DataGridView.DataSourse ==数据源,
还有一种就是空间绑定 了

以上是关于C#中DataGridView控件绑定数据源有几种方式?的主要内容,如果未能解决你的问题,请参考以下文章