RE: Binding object with object properties

From: Jeffrey Tan[MSFT] (v-jetan_at_online.microsoft.com)
Date: 12/03/04


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.



Relevant Pages

  • RE: DataGrid question
    ... This is because ArrayList class did not implement IBindingList ... Only if the datasource implement this interface, the DataGrid ... private void buttonRemove_Click(object sender, System.EventArgs e) ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Re: Displaying a Collection of Objects in a DataGrid
    ... "Guy Thornton" wrote: ... interface is returning a null reference exception in System.dll. ... If you want grid and other controls to be updated automatically, ... am trying to display the collection of objects in a datagrid. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Switch on GET/SET accessor
    ... I think in your last reply, the word "grid" refers to the WinForm DataGrid ... I think this can be done through implementing ICustomTypeDescriptor ... This interface enable you to create or remove the a class's ... This posting is provided "as is" with no warranties and confers no rights. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Databinding - Best Practice (object-oriented)
    ... > provides all the databinding stuff you need to do exactly what you want. ... >> I would like to know your opinions about the best way of implementing ... >> datagrid and we can easily save the data back to the database. ... For example if every time an employee is created or modified ...
    (microsoft.public.dotnet.framework.windowsforms.databinding)
  • Re: Databinding - Best Practice (object-oriented)
    ... > provides all the databinding stuff you need to do exactly what you want. ... >> I would like to know your opinions about the best way of implementing ... >> datagrid and we can easily save the data back to the database. ... For example if every time an employee is created or modified ...
    (microsoft.public.dotnet.framework.windowsforms)

Loading