C#.NET question - how the heck do I display a 2D array in a windows form?

notfred

Lifer
Feb 12, 2001
38,241
4
0
What I want is something that looks kind of like an Excel window. It's basically a table of cells. It's not connected to a database, it doesn't require any schemas, nothing complex.


Just a 2D array laid out in a table. How do I do that?
 

UCJefe

Senior member
Jan 27, 2000
302
0
0
Originally posted by: notfred
there's got to be some way to do this?


There is, but it's probably not as easy as you would like. One approach is to use the DataGrid control which will give you your table that you are looking for. Unfortunately, DG's can't bind to a multi-dimensional array. So you have to build a DataTable from your multidimensional array and then bind that to your DG. There are probably a million other ways to do this depending on what type of control you want but something like the following should work.
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Originally posted by: UCJefe
Originally posted by: notfred
there's got to be some way to do this?


There is, but it's probably not as easy as you would like. One approach is to use the DataGrid control which will give you your table that you are looking for. Unfortunately, DG's can't bind to a multi-dimensional array. So you have to build a DataTable from your multidimensional array and then bind that to your DG. There are probably a million other ways to do this depending on what type of control you want but something like the following should work.

Thank you. :) That code isn't 100% perfect, but it looks like a good starting point.