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 Data Binding / December 2004

Tip: Looking for answers? Try searching our database.

Binding object with object properties

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
kh - 02 Dec 2004 16:01 GMT
Hi. I've been reading up about preparing objects for binding to Windows Forms
controls. However, I have not seen anything about how to get a control to
show an object with it's non value-type properties expanded.

For example consider the following. I want to bind a collection of
OuterObjects to a DataGrid, but the properties of the InnerObject property
are not expanded. All I get is the class name displayed as a column, wheras I
want to see InnerObject's "Name" property as a column. How do I do this
without creating a wrapper?

public class OuterObject
{
   ...
   public InnerObject InnerObject
   {
       get{return innerObject;}
   }
}
public class InnerObject
{
   ...
   public string Name
   {
       get{return name;}
       set{name = value;}
   }
   ...
}

Thanks

kh
"Jeffrey Tan[MSFT]" - 03 Dec 2004 03:07 GMT
Hi,

Based on my understanding, you want to display the "deep" property of your
custom class in DataGrid Column.

Currently, .Net databinding still does not support deep databinding for
datasource. For your senario, the winform datagrid can only reflect the
first level properties of OuterObject class, then use these property type's
string representation for the first level property as column text.

For your requirement of display the deep property, the simplest way is
overriding InnerObject class's ToString() method, just return
InnerObject.Name property as the "InnerObject" type's string
representation. This is a little trick, which just change the type's string
representation logic to workaround this issue. But this trick will change
entire InnerObject class's string representation logic, which you may do
not want to do.

The solid solution for this issue is implement ICustomTypeDescriptor
interface for your OuterObject, this interface gives "OuterObject" a
description of the properties and enables you to create or remove or modify
the a class's properties at runtime. We can override
ICustomTypeDescriptor.GetProperties method, then find the "InnerObject"
property and return this inner "Name" property.

But for DataGrid to query the ICustomTypeDescriptor interface of
OuterObject class, we should implement a strong typed collection of
OuterObject, which implemented ITypedList interface. Then the DataGrid will
call ICustomTypeDescriptor interface when doing databinding.

For more information, please refer to my original post:
http://groups.google.com/groups?hl=zh-CN&lr=&c2coff=1&threadm=4K6Ioo3fEHA.33
40%40cpmsftngxa06.phx.gbl&rnum=2&prev=/groups%3Fq%3D%2BICustomTypeDescriptor
%2BDataGrid%2BITypedList%2B%2522Jeffrey%2522%26hl%3Dzh-CN%26lr%3D%26c2coff%3
D1%26selm%3D4K6Ioo3fEHA.3340%2540cpmsftngxa06.phx.gbl%26rnum%3D2

For example of how to implement ITypedList and ICustomTypeDescriptor,
please refer to the following article:
http://weblogs.asp.net/fbouma/articles/115837.aspx
http://www.codeproject.com/cs/database/itypedlist.asp?df=100&forumid=15239&e
xp=0&select=491147

Hope this helps
=======================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

kh - 03 Dec 2004 08:41 GMT
Jeffrey

Awesome. Thanks for your reply.

kh

> Hi,
>
[quoted text clipped - 49 lines]
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
"Jeffrey Tan[MSFT]" - 06 Dec 2004 01:12 GMT
Hi,

You are welcome!! If you have any other questions, please feel free to
feedback. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


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.