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

发布时间 2023-09-26 12:46:39作者: funiyi816

第一种:
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绑定数据源的几种方式
使用DataGridView控件,可以显示和编辑来自多种不同类型的数据源的表格数据。

将数据绑定到DataGridView控件非常简单和直观,在大多数情况下,只需设置DataSource属性即可。在绑定到包含多个列表或表的数据源时,只需将DataMember属性设置为指定要绑定的列表或表的字符串即可。