Can I get the item type from a BindingSource?

Posted by Preston on Stack Overflow See other posts from Stack Overflow or by Preston
Published on 2010-06-14T19:06:33Z Indexed on 2010/06/14 19:12 UTC
Read the original article Hit count: 241

Filed under:
|
|
|

I would like to get the Type of item that a BindingSource is hooked up to or configured for. The BindingSource.DataSource property can be set to an object, list, or type. If it is a Type, it obviously does not have an bound item yet, but I would still like to get the Type. For a List, I need the item Type, not the list type.

There is a method BindingSource.GetItemProperties, that accomplishes most of what I need. It gets the PropertyDescriptors for the Type, list item, or object specified by the DataSource and DataMember.

The reason I ask, is that I have some components that I would like to re-use, but they are currently setup to work off of an item Type. The Type is mainly used to get PropertyInfos and then build a UI, but PropertyInfo and PropertyDescriptor is not exactly the same, so it is not immediately apparent that they can be reworked to use a PropertyDescriptor collection instead. Then there is cascading refactoring of everything already using these components and that adds up to a lot of work that I would rather not do.

I've looked through the API docs for for a good way to do this, but so far I have not had any luck. Am I missing something or is this just something I can not or should not be doing?

© Stack Overflow or respective owner

Related posts about c#

Related posts about vb.net