Creating datagrid view from an two-dimensional array

  • Thread starter Thread starter mirek
  • Start date Start date
M

mirek

Hello,

is there a way how to create data view (via datagrid) of a 2dim. array?
I've data which I've got via SOAP call - it is a customer list, I want to simply
display it in an datagrid. Can someone point me to an example how to do it?


thanx

Mirek
 
mirek,

This isn't easy. While Array implements IList, the grid will reflect on
the properties of each value in the array, which in turn are another array
(which is a jagged array).

In order to get around this, you will want to create a class which
implements ICustomTypeDescriptor, or a class which has properties that map
to the horizontal dimension of your array. Then, create these classes, and
assign the values to each instance (each instance is a row). You will then
have an array of these, which you can pass to the data grid.

Your other option is to create a data set, and populate it manually, and
then bind to that.

Hope this helps.
 
Nicholas said:
mirek,

This isn't easy. While Array implements IList, the grid will reflect on
the properties of each value in the array, which in turn are another array
(which is a jagged array).

In order to get around this, you will want to create a class which
implements ICustomTypeDescriptor, or a class which has properties that map
to the horizontal dimension of your array. Then, create these classes, and
assign the values to each instance (each instance is a row). You will then
have an array of these, which you can pass to the data grid.

Your other option is to create a data set, and populate it manually, and
then bind to that.

Hope this helps.
Ok, but can this be automated? When I'm accessing web service via SOAP, I can
make proxy using wsdl.exe - from wsdl documet, which describes also datastructures.
Isn't there a way how to use it?

TIA

mirek
 
mirek,

No, not really, because the structure of the data isn't such that it
binds to the grid easily. Either get the data into a data set, or you have
to create the intermediary class.

It's not really that hard, actually, to just stuff it into a data set.
 
Nicholas Paldino [.NET/C# MVP] napsal(a):
mirek,

No, not really, because the structure of the data isn't such that it
binds to the grid easily. Either get the data into a data set, or you have
to create the intermediary class.

It's not really that hard, actually, to just stuff it into a data set.
So thank you, very much, for informations. Now I have to go to study ;)


thanx

Mirek
 
Back
Top