Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I get the item type from a BindingSource?

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 a bound item yet, but I would still like to get the Type. For a List, I need the item Type, not the list type.

I currently have a custom list type for business objects that implement an IListItemType interface, that I created to solve this problem a while back. I would now like to get this working in a more generic fashion so that it will work with any list.

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?

like image 217
Preston McCormick Avatar asked Dec 22 '22 02:12

Preston McCormick


1 Answers

I recently ran across the ListBindingHelper class in the framework that has everything I was looking for:

System.Windows.Forms.ListBindingHelper.GetListItemType()

Returns the type of an item contained in a list or collection.

ListBindingHelper.GetListItemProperties()

Returns a PropertyDescriptorCollection that describes the properties of the items contained in the list.

like image 112
Preston McCormick Avatar answered Jan 02 '23 15:01

Preston McCormick