Datagrid displaying related ArrayLists

C

Christiaan

Hi,
I have two classes, Department and Employer, the Department contains an
ArrayList (employers) filled with Employer objects. I want to display an
ArrayList filled with Department objects using a Datagrid. Therefor, I do a
setDatabinding with the Deparments ArrayList and I create two
DatagridTableStyle objects, both with mappingname "ArrayList", and add them
to the Datagrid. However, if I want to add the second DatagridTableStyle, I
get the exception that a table with mappingname "ArrayList" already exists
(makes sense). If I change the Deparment ArrayList to a strongly type array
Department[], and change the mappingname accordingly all works well, of
course. (great feature by the way). I want to know whether it is possible to
display this kind of objectstructure using just ArrayLists.

kind regards,
Christiaan
 
K

Kevin Yu [MSFT]

Hi Christiaan,

Thanks for posting in the group. We are currently researching on this issue
and will update your ASAP.

If there is anything unclear, please feel free to post in the community and
we will follow up.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
J

Jeffrey Tan[MSFT]

Hi Christiaan,

Thank you for posting in the community!

Based on my understanding, you want to specify 2 ArrayLists of
DatagridTableStyle for the same datagrid.

==========================================
If you want to bind your datagrid to arraylist object, all items in the
arraylist must be of the same type as the first item. And when binding to
an ArrayList, you must set the MappingName of the DataGridTableStyle to
"ArrayList" (the type name).

In the document of GridTableStylesCollection class, you will see that:
"CAUTION ...... Consequently, an exception will be thrown if you try to
add new DataGridColumnStyle objects with duplicate MappingName values to
the GridColumnStylesCollection. Alternatively, clear the
GridColumnStylesCollection using the Clear method."
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemwindowsformsgridtablestylescollectionclasstopic.asp

So DataGrid.TableStyles does not support 2 DatagridTableStyles with the
same MappingName.

I think your workaround of using array is a simple and good.

Another workaround I can think of is creating a new class which inherited
from the ArrayList class, then you can specify different MappingName.

============================================
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.
Have a nice day!!

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.
 
J

Jeffrey Tan[MSFT]

Hi Christiaan,

Does my reply make sense to you?
If you still have anything unclear, please feel free to tell me, I will
help you.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top