您的位置:首页 > 编程语言 > C#

C# DataGridView控件绑定数据源的方式

2016-11-07 23:08 651 查看
注:

直接添加并绑定数据库,要删除的话,需(?)删除数据库中的数据,然后重新给DATAGRIDVIEW绑定数据源,使用
dataGridView.Row.Clear()
无效。

第一种:

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>);


以后待阅读:

DataGridView控件—绑定数据方法
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c#