BindingList 和列灵活性
每个人都对 BindingList 代替 DataTable 赞不绝口。
你们如何克服列灵活性的问题? 对于 BindingList,我需要定义并实现 T 对象。 如果需要添加任何新列,我需要向 T 对象添加新属性......而在 DataTable 中这要容易得多。
BindingList<T> samples = new BindingList<T>();
这是你必须忍受的事情还是有一个相对简单的方法来克服它?
使用c# 2.0,框架紧凑。
Everyone raves about BindingList in place of DataTable.
How do you guys overcome the problem of column flexibility? For BindingList I need to define and implement T object. If any new columns needed to be added, I need to add new properties to T object....while in DataTable this is much easier.
BindingList<T> samples = new BindingList<T>();
Is that something you live with or is there a relatively easy way to overcome thing?
using c# 2.0, compact framework.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 DataTable 仍然有(偶尔)的优点 - 列灵活性就是其中之一。 话虽这么说,但也有缺点。
此博文。
我个人的经验法则是使用
BindingList
绑定到业务对象的集合。 在这种情况下,列问题就消失了(您已经提前知道有用的列),并且感觉更加自然。如果您绑定到未知事物并尝试在运行时进行解析,DataTable 仍然很有用。
There are still (occasional) advantages to using DataTable - and having column flexibility is one of them. That being said, there are cons as well.
A small comparison of advantages and disadvantages to each are listed in this blog post.
My personal rule of thumb is to use
BindingList<T>
to bind to a collection of business objects. In this case, the column issue goes away (you know the columns that are useful in advance already), and it feels much more natural.DataTable is still useful if you're binding to an unknown thing, and trying to do the parsing at runtime.