日期:2014-05-19  浏览次数:20673 次

控件的datasource问题
控件,比如combobox   ,listbox,grid等等的datasource有什么用处。
直接给他们用myDataTable.Rows赋值有出错。哪位高手讲讲清楚呢?
谢谢!

------解决方案--------------------
myDataTable.Rows不行,你要用myDataTable.

一般来说一个对象要做为DataSource必需有如下的特性:
IList 接口,包括一维数组。

IListSource 接口,例如,DataTable 和 DataSet 类。

IBindingList 接口,例如,BindingList 类。

IBindingListView 接口,例如,BindingSource 类。


------解决方案--------------------
DataTable table=(DataTable)DataGrid.datasource;
table.Row.Add(.......)
DataGrid.datasource=table;
DataGrid.DataBind();