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?
Alex Passos - 07 Apr 2005 14:37 GMT
I don't think the array is a valid data source:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlr
fsystemwindowsformsdatagridclassdatasourcetopic.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[i];
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
>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?
Rhea Bockhorst - 08 Apr 2005 01:21 GMT
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.
> 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?
Alex Passos - 08 Apr 2005 15:42 GMT
I think you can use ArrayList as the source, but this is not the same as
double [] numbers.
Alex
> Alex,
>
[quoted text clipped - 10 lines]
>>
>> What am I doing wrong?
Matt Berther - 08 Apr 2005 01:58 GMT
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.
--
Matt Berther
http://www.mattberther.com
> 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?
Rhea Bockhorst - 08 Apr 2005 16:09 GMT
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;
> Hello Rhea,
>
[quoted text clipped - 10 lines]
> >
> > What am I doing wrong?