talk WebForm:
data listing control:
their common method of setting data source:
then the format of the data source, whether what's required? The easiest way is just to get hold of, and then wait for it to throw an exception:
from the above errors can see out, basically supports three data source binding way: IListSource, IEnumerable, IDataSource.
talk Winform
data listing control:
their common method of setting data source:
the same way and found that it is not life and death thrown exception, through the DataGridView DataSource View Code:
an insufficient look at what the ComboBox DataSource:
tips can be obtained from the above information, the data source support: IListSource interface.
see WPF
data listing control:
their common method of setting data source:
for WPF, it is no longer the ItemsSource of type Object, but IEnumerable:
tips can be obtained from the above information, the data source support: IEnumerable interface.
three comparison:
WebForm: IListSource, IEnumerable, IDataSource.
Winform: IListSource
WPF: IEnumerable
in common:
Because IListSource interface is implemented there must return IList, and IList interface itself has inherited from IEnumerable interface.
so the final common is both the IEnumerable interface that is popular support: List
different points: (with IDataReader, DataTable, DataSet and other generic collection to illustrate)
WebForm: Support IDataReader, DataTable, DataSet.
Winform: does not support IDataReader, support DataTable, DataSet.
WPF: Support IDataReader, does not support the DataTable, DataSet.
there again some story:
Winform: the shrimp does not support IDataReader?
For DataGridView control list, in fact, can be directly modified form, and the modified value will be changed directly back to the bound data source.
may be out of this nature, the IDataReader for read-only, it is not suitable for reading and writing DataGridView control on dual-demand, so do not support.
Winform the DataTable bound:
For List
Therefore, designers come up with: PropertyDescriptor and < span style = "line-height: 1.5;"> ICustomTypeDescriptor other attributes describe a set of norms to realize the value of a custom class and bind problem.
WPF: DataTable does not even consider support:
say MDataTable
MDataTable CYQ.Data data layer is a very important framework of a set of classes and achieve a complete mapping between databases, but also shoulder and various UI to deal with, of course, without it I can not to study a variety of binding.
For custom MDataTable data source bound list controls in this way, a few years ago, I studied for a long time, then the most stable implemented as:
public class MDataTable: IDataReader, IEnumerable, IListSource
why MDataTable DataTable in WPF and under the same ineffective?
why binding but the results invalid?
solution:
IListSource will cause WPF binding fails, then this interface is removed and found WPF to normal.
But the problem again, Winform rely on the IListSource interface to bind and remove the IListSource, in winform is not normal.
After some pondering, considering DataTable rely DataTableView way to bind WPF, I flashed a trick:
Description:
Summary:
although you usually these lists and controls each other, but estimates of binding mechanism, is still relatively small, after all, requires a certain fate.
today when the contents of a reference until one day fate comes, when necessary, come review my article also.
没有评论:
发表评论