RE: Binding object with object properties
From: Jeffrey Tan[MSFT] (v-jetan_at_online.microsoft.com)
Date: 12/03/04
- Next message: Phillip Engle: "failure of combobox to bind to DBNull"
- Previous message: James: "A good debug tool."
- In reply to: kh: "Binding object with object properties"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 03 Dec 2004 03:07:25 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
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
- Next message: Phillip Engle: "failure of combobox to bind to DBNull"
- Previous message: James: "A good debug tool."
- In reply to: kh: "Binding object with object properties"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|