Hello,
I've a little problem with databinding an EntityCollection(of Entity) in a DataGrid.
Let's say i've one entity IncidentEntity and this entity has one property of type AddressEntity (1-1 relation).
In the DataGridView (simple .Net DataGridView), I want to show some properties of the incident and in one column show the address information.
Address information are defined like this : I overrided the ToString() method of the AddressEntity to concat some properties (Street Code + Street + Town + City).
Well, Now if i want to show address information I can create a new property on the IncidentEntity
Public ReadOnly Property AddressInfo() As String
Get
If Me.Address IsNot Nothing Then
Return Me.Address.ToString()
Else
Return Nothing
End If
End Get
End Property
But, i don't want of this
So, I read Frans' article on Complex Databinding and ITypedList. I decided to use PropertyDescriptor and ITypedList.GetItemProperties().
But i'm not sure of using it in the best way...
I call GetItemProperties() on the DefaultView of the EntityCollection(of IncidentEntity).
After I search in the propertyCollection the propertyDescriptor corresponding to the AddressProperty of the IncidentEntity. I remove it, and add a new AddressPropertyDescriptor to the collection.
Public Class AddressPropertyDescriptor
Inherits PropertyDescriptor
Public Overrides Function GetValue(ByVal component As Object) As Object
Dim obj As IncidentEntity = CType(component, IncidentEntity)
If obj.AddressOrderedSpNo IsNot Nothing Then
Return obj.AddressOrderedSpNo.ToString()
Else
Return String.Empty
End If
End Function
End Class
I'm not very happy of this design... do you see a better way to achieve this ?
Cheers,
Ben