ICustomTypeDescriptor - список дочерних свойств не может быть привязан - PullRequest
0 голосов
/ 13 июля 2020

Я хочу иметь возможность добавлять настраиваемые столбцы во время выполнения для отображения в DataGridView, поэтому я реализовал интерфейс ICustomTypeDescriptor. Затем я получаю исключение при попытке привязать дочерний список к этому объекту. Моя реализация ICustomTypeDescriptor приведена ниже:

Public Function GetAttributes() As AttributeCollection Implements ICustomTypeDescriptor.GetAttributes
    Return TypeDescriptor.GetAttributes(Me)
End Function

Public Function GetClassName() As String Implements ICustomTypeDescriptor.GetClassName
    Return TypeDescriptor.GetClassName(Me)
End Function

Public Function GetComponentName() As String Implements ICustomTypeDescriptor.GetComponentName
    Return TypeDescriptor.GetComponentName(Me)
End Function

Public Function GetConverter() As TypeConverter Implements ICustomTypeDescriptor.GetConverter
    Return TypeDescriptor.GetConverter(Me)
End Function

Public Function GetDefaultEvent() As EventDescriptor Implements ICustomTypeDescriptor.GetDefaultEvent
    Return TypeDescriptor.GetDefaultEvent(Me)
End Function

Public Function GetDefaultProperty() As PropertyDescriptor Implements ICustomTypeDescriptor.GetDefaultProperty
    Return TypeDescriptor.GetDefaultProperty(Me)
End Function

Public Function GetEditor(editorBaseType As Type) As Object Implements ICustomTypeDescriptor.GetEditor
    Return TypeDescriptor.GetEditor(Me, editorBaseType)
End Function

Public Function GetEvents() As EventDescriptorCollection Implements ICustomTypeDescriptor.GetEvents
    Return TypeDescriptor.GetEvents(Me)
End Function

Public Function GetEvents(attributes() As Attribute) As EventDescriptorCollection Implements ICustomTypeDescriptor.GetEvents
    Return TypeDescriptor.GetEvents(Me, attributes)
End Function

Public Function GetProperties() As PropertyDescriptorCollection Implements ICustomTypeDescriptor.GetProperties
    Return GetPropertyDescriptors()
End Function

Public Function GetProperties(attributes() As Attribute) As PropertyDescriptorCollection Implements ICustomTypeDescriptor.GetProperties
    Return GetPropertyDescriptors()
End Function

Public Function GetPropertyOwner(pd As PropertyDescriptor) As Object Implements ICustomTypeDescriptor.GetPropertyOwner
    Return Me
End Function

Protected Function GetPropertyDescriptors() As PropertyDescriptorCollection
    If PropertyDescriptorList Is Nothing Then
        Dim properties As New List(Of PropertyDescriptor)
        For Each desc As PropertyDescriptor In TypeDescriptor.GetProperties(Me.GetType())
            properties.Add(desc)
        Next

        For Each aProp In DynamicPropDict
            Dim Attributes As AttributeCollection = Nothing
            If DynamicAttrPropDict.ContainsKey(aProp.Key) Then
                Attributes = New AttributeCollection(DynamicAttrPropDict(aProp.Key).ToArray)
            Else
                Attributes = New AttributeCollection
            End If
            If aProp.Value IsNot Nothing Then
                properties.Add(New BODynamicPropertyDescriptor(Me, aProp.Key, aProp.Value.GetType(), Attributes))
            Else
                properties.Add(New BODynamicPropertyDescriptor(Me, aProp.Key, GetType(Object), Attributes))
            End If
        Next

        PropertyDescriptorList = New PropertyDescriptorCollection(properties.ToArray())
    End If

    Return PropertyDescriptorList
End Function

Это исключение, которое я получаю

Я получаю все существующие свойства с помощью TypeDescriptor.GetProperties (Me.GetType ()), и свойство дочернего списка добавляется в список, поэтому я не понимаю, почему привязка больше не может его найти. Есть ли у кого-нибудь идеи, что я делаю неправильно?

Обновление: добавлены сведения об исключении:

System.ArgumentException
HResult=0x80070057
Message=DataMember property 'AddressList' cannot be found on the DataSource.
Source=System.Windows.Forms
StackTrace:
at System.Windows.Forms.ListBindingHelper.GetList(Object dataSource, String dataMember)
at System.Windows.Forms.BindingSource.ResetList()
at System.Windows.Forms.BindingSource.DataSource_Initialized(Object sender, EventArgs e)
at System.Windows.Forms.BindingSource.OnInitialized()
at System.Windows.Forms.BindingSource.System.ComponentModel.ISupportInitialize.EndInit()
at KAI.OctopusPMI.Accounting.PLMaintSupplierEditView_BO.InitializeComponent()
in E:\DevelopmentVSTS\OctopusPMI\OctopusPMIV5\V5.0.99.9999\Source\Business Modules\Accounting\Accounting\Ledgers\Purchase\Supplier\PLMaintSupplierEditView_BO\PLMaintSupplierEditView_BO.Designer.vb:line 4430
at KAI.OctopusPMI.Accounting.PLMaintSupplierEditView_BO..ctor() in E:\DevelopmentVSTS\OctopusPMI\OctopusPMIV5\V5.0.99.9999\Source\Business Modules\Accounting\Accounting\Ledgers\Purchase\Supplier\PLMaintSupplierEditView_BO\PLMaintSupplierEditView_BO.vb:line 15
This exception was originally thrown at this call stack:
[External Code]
KAI.OctopusPMI.Accounting.PLMaintSupplierEditView_BO.InitializeComponent() in PLMaintSupplierEditView_BO.Designer.vb
KAI.OctopusPMI.Accounting.PLMaintSupplierEditView_BO.New() in PLMaintSupplierEditView_BO.vb
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...