System.Windows.Forms.ListBindingHelper.GetListItemProperties C# (CSharp) Method

GetListItemProperties() public static method

public static GetListItemProperties ( object list ) : System.Windows.Forms.PropertyDescriptorCollection
list object
return System.Windows.Forms.PropertyDescriptorCollection
        public static PropertyDescriptorCollection GetListItemProperties(object list) {
            PropertyDescriptorCollection pdc;

            if (list == null) {
                return new PropertyDescriptorCollection(null);
            } else if (list is Type) {
                pdc = GetListItemPropertiesByType(list as Type);
            }
            else {
                object target = GetList(list);

                if (target is ITypedList) {
                    pdc = (target as ITypedList).GetItemProperties(null);
                }
                else if (target is IEnumerable) {
                    pdc = GetListItemPropertiesByEnumerable(target as IEnumerable);
                }
                else {
                    pdc = TypeDescriptor.GetProperties(target);
                }
            }

            return pdc;
        }

Same methods

ListBindingHelper::GetListItemProperties ( object list, Array listAccessors ) : System.Windows.Forms.PropertyDescriptorCollection
ListBindingHelper::GetListItemProperties ( object dataSource, string dataMember, Array listAccessors ) : System.Windows.Forms.PropertyDescriptorCollection

Usage Example

        /// <include file='doc\ListBindingHelper.uex' path='docs/doc[@for="ListBindingHelper.GetListItemProperties2"]/*' />
        public static PropertyDescriptorCollection GetListItemProperties(object dataSource, string dataMember, PropertyDescriptor[] listAccessors)
        {
            dataSource = GetList(dataSource);

            if (!string.IsNullOrEmpty(dataMember))
            {
                // Find the property on the data source specified by the data member
                PropertyDescriptorCollection dsProps = ListBindingHelper.GetListItemProperties(dataSource);
                PropertyDescriptor           dmProp  = dsProps.Find(dataMember, true);

                // Error: Property not found - data member is invalid
                if (dmProp == null)
                {
                    throw new System.ArgumentException(string.Format(SR.DataSourceDataMemberPropNotFound, dataMember));
                }

                // Add the data member property to the list accessors
                int len = (listAccessors == null) ? 1 : (listAccessors.Length + 1);
                PropertyDescriptor[] listAccessors2 = new PropertyDescriptor[len];
                listAccessors2[0] = dmProp;
                for (int i = 1; i < len; ++i)
                {
                    listAccessors2[i] = listAccessors[i - 1];
                }

                // Replace old accessors with new accessors
                listAccessors = listAccessors2;
            }

            return(GetListItemProperties(dataSource, listAccessors));
        }
All Usage Examples Of System.Windows.Forms.ListBindingHelper::GetListItemProperties