Binding Multidimensional Array to DataGrid

E

epigram

Well, conceptually this is what I want to do. I was hoping to use an
ArrayList to build a (dynamic) array of string arrays, and then bind the
ArrayList object to a DataGrid. I can do that, but it doesn't give me the
results that I wanted. Is there a way to successfully do this? I even
tried to bind a multidimensional array (string [,]) to a DataGrid, but an
exception is thrown with the message "Array was not a one-dimensional
array". I'm using the ArrayList simply as a convenient data structure (like
a table) to store the results of some calculations I am making. I can take
another approach if someone has a suggestion. Any help would be much
appreciated.

Thanks.
 
G

Guest

epigram said:
Well, conceptually this is what I want to do. I was hoping to use an
ArrayList to build a (dynamic) array of string arrays, and then bind the
ArrayList object to a DataGrid. I can do that, but it doesn't give me the
results that I wanted. Is there a way to successfully do this? I even
tried to bind a multidimensional array (string [,]) to a DataGrid, but an
exception is thrown with the message "Array was not a one-dimensional
array". I'm using the ArrayList simply as a convenient data structure (like
a table) to store the results of some calculations I am making. I can take
another approach if someone has a suggestion. Any help would be much
appreciated.

Thanks.

A DataTable is equivalent in function to a multi-dimensional array and it
works nicely with the DataGrid:

DataTable dt = new DataTable();
dt.Columns.Add( new DataColumn("Column1", typeof(Int32)));
dt.Columns.Add(new DataColumn("Column2", typeof(string)));
....
DataRow dr ;
dr= dt.NewRow ();
dr["Column1"] = 1;
dr["Column2"] = "test";
...
dt.Rows.Add (dr);
DataGrid1.DataSource =dt;
DataGrid1.DataBind ();
 

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

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top