Hi Andrea,
Thanks for your posting!!
I will help on your 3 problems one by one:
#1, Defaultly, the Winform datagrid will query the properties of the bound
collection and auto generate the columns with the queried property order.
But, we may control this behavior through explicitly specify several
DataGridTextBoxColumns to the datagrid, each DataGridTextBoxColumn binds to
a property of the datasource object, then the order is determined by our
code. For more details, please refer to DataGridTextBoxColumn class in
MSDN, and the article following:
"Adding Tables and Columns to the Windows Forms DataGrid Control"
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/
vbtskcreatingcustomcolumntypesindatagrid.asp
#2, You may refer to "DataGrid.DataMember Property" in MSDN:
If the DataSource is a DataTable, DataView, collection, or array, setting
the DataMember property throws an exception.
If the DataSource is a DataSet or DataViewManager that contains three
tables named Customers, Orders, and OrderDetails, you must specify one of
the tables to bind to. If the DataSet or DataViewManager contains only one
DataTable, you should set the DataMember to the TableName of that DataTable.
#3, This is a request for deep databinding for Winform datagrid. Currently,
winform datagrid does not support deep databinding, and datagrid can only
query the first level public properties of the item in the colleciton(that
is myProduct's public properties) as columns to display. DataGrid actually
called these first level properties' ToString() method to get the string
representation to be displayed in datagrid cell, so your "Parts" property
of myProduct class can not display its deep property.
If you really want to display a deep property of "Parts" property, I have 2
workarounds:
1, override "Parts" property type class's ToString() method, just return
certain deep property's string representation.
2, The solid solution for this issue is implement ICustomTypeDescriptor
interface for your myProduct , 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 "Parts" property
and return its certain inner property.
But for DataGrid to query the ICustomTypeDescriptor interface of myProduct
class, we should implement a strong typed collection of myProduct , 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 these information makes sense to you.
================================================
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.
a.maggiulli - 17 Dec 2004 10:09 GMT
Hi Jeffrey, thanks for your answer...if you can please clarify some point :
#1. I know I can modify columns order in the UI layer ( writing code for the
data grid ) but i really want to order column in my BusinessObject Layer (
myProducts class ) Is this possible ?? There is an interface the solve this
problem...?
#2 & #3. Semplify point 2 and 3 are the same question : deep databinding for
datagrid . Do you know if this is more easy in Visual Studio 2005 ( .Net
framework 2.0 ) ?? .
Last , if you can tell me a good microsoft book talking about this argoment
( i own many microsoft press book but they don't talk about this question in
details..)
thank you .
-Andrea
> Hi Andrea,
>
[quoted text clipped - 66 lines]
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
"Jeffrey Tan[MSFT]" - 20 Dec 2004 06:37 GMT
Hi Andrea,
Thanks very much for your feedback!!
#1, yes, I see your concern, you want to specify the autogenerated columns
order at the datasource level not the UI level, so that each datagrids bind
to the datasources are of the same specified columns order without setting.
For this, I think we may implement ITypedList interface for the class items
array, then adjust the properties order in GetItemProperties() method, this
is not a simple way, maybe not suitable for you, and I did not suggest you
do this work, and I think the simplest way is just define your class
properties in certain order, then the columns will be the same order as
properties defined.
Actually, I still highly suggested control the columns order at UI level,
because this is the Winform DataGrid databinding's standard columns order
control way and easy to implement.
#2,#3, I am not sure if the release version of VS.net 2005 will support
deep databinding, because VS.net2005 is still in beta version, everything
can be changed. I think you may download the lastest of VS.net 2005 beta
version to test if this is supported.
=========================================
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.
"Jeffrey Tan[MSFT]" - 20 Dec 2004 08:30 GMT
Hi Andrea,
Forget to talk about the book issue :-)
Actually, I usually read the articles in MSDN, there are many good and
resource there. I did not know many books about Winform, but I think Chris
Sells's <Essential Windows Forms> should be a good book for winform issues.
Hope this information makes sense to you.
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.