Create custom DataTable which is bindable to WinForms controls?

喜夏-厌秋 提交于 2020-01-05 07:58:11

问题


Our shop primarily use "ADO objects" (I'm referring to DataSet, DataTable, and DataRow) for marshaling around data and manipulating it on forms and in grids. We are experimenting with creating shop-flavored counterparts to the native ADO objects so that we can impose our in-house standards on top of them.

Implementing this is straightforward with one exception: I want our objects to be bindable to controls.

I'm aware of IList, IBindingList, BindingSource, etc. and have looked at and experimented with these, but I am falling short when it comes to making a class with no hard property names bindable. The native ADO objects are not strongly typed by default. You have column values that you access via the Item property (e.g. row("Age") or row.Item("Age")). The binding examples I've found online deal with strong-typed objects (e.g. row.Age). Essentially, we want to create custom ADO objects (not inherited from the native ones) that still retain their ability to bind to controls.

Is there a bare-bones example of how this could be implemented?

In a grid I would expect to see columns Name, Age and Occupation from a row where these properties are exposed via row("Name"), row("Age") and row("Occupation"). This must be doable as this is exactly what the native DataTable and DataRow provide.

This is a refinement of an earlier question.


回答1:


It seems you need to use the ITypedList interface, which works in conjunction with PropertyDescriptor. The clearest article I have found on this is here:

http://blog.lab49.com/archives/705

I had attempted this myself a while back, and will be giving it another try based on this article.



来源:https://stackoverflow.com/questions/7192379/create-custom-datatable-which-is-bindable-to-winforms-controls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!