Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Controls / March 2006

Tip: Looking for answers? Try searching our database.

Binding Nested Business Objects to Datgridview

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
procom_net_programmer - 29 Mar 2006 22:51 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.