Just starting to use 2.0, and doing some databinding to the DatGridView
of business objects as you described on your page. I have an
collection of objects. The object then contains an object as well. I
am actually trying to display information from both the outer object
and the inner object. Here's some code that will hopefully make more
sense:
Public Class AgencyContact
Private _Agency_Contact_ID As Integer
Private _Contact_ID As Integer
Private _contact As New Contact
Public Property Agency_Contact_ID() As Integer
Get
Return _Agency_Contact_ID
End Get
Set(ByVal Value As Integer)
_Agency_Contact_ID = Value
End Set
End Property
Public ReadOnly Property Contact() As Contact
Get
Return _contact
End Get
End Property
End Class
Public Class Contact
Private _contact_id As Integer
Private _last_name As String
Public Overridable Property contact_id() As Integer
Get
Return _contact_id
End Get
Set(ByVal Value As Integer)
_contact_id = Value
End Set
End Property
Public Property last_name() As String
Get
Return _last_name
End Get
Set(ByVal Value As String)
_last_name = Value
End Set
End Property
End Class
Based on this code, I am trying to set the
DatagridViewColumn.DataPropertyName to "Contact.last_name" and it is
dispalying blank.
I have no problems displaying agency_contact_id in the grid, and if I
set the DataPropertyName to "Contact", I get the object type -
"BusinessLibrary.Contact". I've overridden the ToString method of the
Contact object, and I got the last_name to display. SO I know that the
data is being pulled correctly, it just cannot seem to display complex
objects. Would you have any suggestions, or ideas where to post.
Thanks for your help,
Markus - 30 Mar 2006 06:58 GMT
> Based on this code, I am trying to set the
> DatagridViewColumn.DataPropertyName to "Contact.last_name" and it is
[quoted text clipped - 7 lines]
> display complex objects. Would you have any suggestions, or ideas
> where to post. Thanks for your help,
Try the DataGridView.CellFormatting event.
http://msdn2.microsoft.com/en-US/library/system.windows.forms.datagridview.cellf
ormatting(VS.80).aspx
hth
Markus