【发布时间】:2018-01-01 15:59:52
【问题描述】:
DataGrid 数据绑定错误
class Test1
{
public DataTable table1 = new DataTable();
public BindingSource sr = new BindingSource();
}
class Test2
{
Test1 ta =new Test1();
DataTable table1 = new DataTable();
table1.Columns.Add("Dosage", typeof(int));
table1.Columns.Add("Drug", typeof(string));
table1.Columns.Add("Patient", typeof(string));
table1.Columns.Add("Date", typeof(DateTime));
table1.Rows.Add(25, "Indocin", "David", DateTime.Now);
table1.Rows.Add(50, "Enebrel", "Sam", DateTime.Now);
table1.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now);
table1.Rows.Add(21, "Combivent", "Janet", DateTime.Now);
table1.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now);
ta.table1 = table1 ;
datagridview dgv = new datagridview();
dgv.AutoGenerateColumns = true ;
dgv.DataBindings.Add("DataSource",ta,"table1");
}
上面的代码给了我“无法绑定到 DataSource.Parameter 名称上的属性或列 table1:dataMember。” .我在这里犯了什么错误,我不明白。任何人都可以帮助我吗?
【问题讨论】:
-
不要拨打
DataGridViewaGridView或DataGrid,反之亦然!!这是错误且令人困惑的,因为它们是不同的控件。总是用正确的名字来称呼事物!
标签: c# winforms data-binding datagrid