Array in DataGrid

netpicker9

Member
Joined
Dec 8, 2004
Messages
17
Programming Experience
1-3
Hi,

I have Array of values and i want to populate them into DataGrid.
Array is like this (in rows)

1st Row:
One 500 40% Description
2nd Row:
Two 600 34% bla bla
.
.
.
Nth Row:
XYZ 898 47% something

How to show this in Grid?
Thanks
 
I assume that you mean that your array is two-dimensional. First of all it is a bad idea to use a multidimensional array for that type of data. If each "column" means something completely different then you should not use multidimensional array, but rather a Datatable or a one dimensional array of objects with a property that corresponds to each column.

Further, it's not possible to display a multidimensional array in a DataGrid or, seeing that you're using VB 2005, a DataGridView. The object you bind to the grid must have a property descriptor for each column to be displayed. A DataTable has a property descriptor for each column. Given that a multidimensional array doesn't have true columns it does not have property descriptors. You would need to define a class or structure that has a property for each of your columns. You can then create a one-dimensional array of those objects, which will then have a property descriptor for each property. The grid will then create a column for each property.

If you are determined to stick with a multidimensional array then your only option is to use an unbound grid and insert the data manually into each cell.
 
Back
Top