Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / April 2005

Tip: Looking for answers? Try searching our database.

DataGrid in Winforms

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rhea Bockhorst - 07 Apr 2005 14:03 GMT
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?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.