Groups | Blog | Home
all groups > dotnet windows forms databinding > june 2005 >

dotnet windows forms databinding : Databinding of 2d-Arrays in a DataGrid


MichaelGeier
6/28/2005 5:21:05 AM
Hello,
I have a 2d Array say

Array* pArray=Array::CreateInstance(__typeof(int),5,4);

and want to bind this Array to a DataGrid.

DataGrid* pDS=new DataGrid();
pDS->DataSource=pArray;

This is not allowed. because a DataGrid supplies only 1d-Arrays.

Who knows a workaround? Maybe to wrap the array and implement the
IListSource Interface in the wrapper? If yes, how?

Thanks in advance
Michael

P.S.: To copy the 2d-Array into a Datatable is not recommended for me.

MichaelGeier
6/29/2005 1:23:01 AM
Jeffrey,
thanks for your reply.

I know the webpage you offer to me. I think it dont cover the binding of
2d-Arrays.
Maybe you have additional information


[quoted text, click to view]
v-jetan NO[at]SPAM online.microsoft.com (
6/29/2005 7:45:40 AM
Hi Michael,

Thanks for your post.

To implement IListSource interface, we have to do a lot of work. And we
have to implement several interfaces. For more information, please refer to:
"HOWTO: implement IListSource in Winforms v2"
http://noiseehc.freeweb.hu/IListSource.html

Thanks

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.
v-jetan NO[at]SPAM online.microsoft.com (
6/30/2005 9:07:47 AM
Hi Michael,

Thanks for your feedback.

First, Winform datagrid does not support 2 dimension array databinding. If
we create a 2 dimension array as the datasource, the Winform will throw an
System.ArgumentException: "Array was not a one-dimensional array". So we
can not bind 2 dimension array to DataGrid.

However, for your request, the most close effect should be DataTable. Also,
we may create a customized class which implement IListSource interface
which has the similar effect as DataTable, however, we still have to
copy(or assign) the array items to the class items with code, and I do not
think it has any better aspect than using DataTable.

So currently, the 2 dimension array databinding is not supported for
DataGrid, we'd better create the 2 dimension with the DataTable.

Hope this helps

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.
MichaelGeier
6/30/2005 11:01:02 PM
Thanks again Jeffrey,
it seemed to be hard stuff to make a 2d-Array bindable.
What is with .Net Version 2.0? Maybe the new DataGridView accept a 2d-Array
as a DataSource?

Michael

[quoted text, click to view]
v-jetan NO[at]SPAM online.microsoft.com (
7/1/2005 6:34:35 AM
Hi Michael,

Thanks for your feedback.

Currently, I have not tested this on VS.net2005, however, it seems that
this has been reported as a limitation, which will be updated in the future
document. The public link for this issue is:
"Bug Details: Binding arrays to a datagrid"
http://lab.msdn.microsoft.com/ProductFeedback/viewFeedback.aspx?feedbackid=1
308ae72-bdee-4316-b8c2-35c32854892a

So I think this will not be supported in VS.net2005. Anyway, you can free
download Whidbey beta2 for a test. Hope this helps

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.
AddThis Social Bookmark Button