DataGrid in Winforms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using an arrary of double as the DataSource of a DataGrid object, but
the DataGrid window contains nothing.

What am I doing wrong?
 
I don't think the array is a valid data source:

http://msdn.microsoft.com/library/d...mwindowsformsdatagridclassdatasourcetopic.asp

You can create a disconnected data set and populate it with the values:

DataSet ds = new DataSet("Array of Doubles");
DataTable dt = new DataTable("Doubles");
dt.Add(new DataColumn("Number", typeof(double)));

for(int i = 0; i < myarray.Length; i++) {
DataRow dr = dt.NewRow();
dr["Number"] = myarray;
dt.Rows.Add(dr);
}

ds.Tables.Add(dt);

grid.DataSource = ds;

Conversely you only really need the DataTable portion to make this work but
later if you want to add more tables the code above should work nicely.

Alex
 
Alex,

Thanks for the reply.

I would think that C# would have a slicker way to display an array in a
Datagrid control. From the documentation I get that an array can be a data
source for a Datagrid object. But when I set the Datagrid source to the
array, nothing is displayed.
 
Hello Rhea,

Can you provide the bit of code that you're using to hook up the datagrid?
You should be able to provide any IList implementation to the data source
property.
 
I think you can use ArrayList as the source, but this is not the same as
double [] numbers.

Alex
 
Matt,

What I'm doing is very simple. so I'm probably leaving something out

private System.Windows.Forms.DataGrid datagrid;
double[] x = new double[10];
datagrid.DataSource = x;
 
Back
Top