471,321 Members | 2,104 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,321 software developers and data experts.

Can't get a my DataGrid to work .. I'm busted or its busted

bob
I cannot seem to display any info with my Data Grid ... the online examples
I have seen 'appear' to say the same thing.
create a DataTable then simply call something like this myDataGrid.Source =
myDataTable. I'm missing something fundemental here cos I get big black
nothing.

here's some code snippets.

public class Form1 : System.Windows.Forms.Form
{
// declarations section

private System.Windows.Forms.DataGrid dataGrid1;
private DataTable myDataTable2;
private DataColumn myColumn2;
private DataRow myRowItem2;

private void Form1_Load(object sender, EventArgs e)
{// create an in memory database
myDataTable2 = new DataTable("Machine_Events2");
myColumn2 = new DataColumn("ID", System.Type.GetType("System.Int32"));
myDataTable2.Columns.Add( myColumn2 );
myColumn2 = new DataColumn("theTime", System.Type.GetType("System.String"));
myDataTable2.Columns.Add( myColumn2 );
myColumn2 = new DataColumn("machine_state",
System.Type.GetType("System.String"));
myDataTable2.Columns.Add( myColumn2 );

myRowItem2 = myDataTable2.NewRow();
myRowItem2["ID"] = 1;
myRowItem2["theTime"] = "Some time";
myRowItem2["machine_state"] = "Some_State";
myDataTable2.Rows.Add(myRowItem2);

myRowItem2 = myDataTable2.NewRow();
myRowItem2["ID"] = 2;
myRowItem2["theTime"] = "more time";
myRowItem2["machine_state"] = "Another_State";
myDataTable2.Rows.Add(myRowItem2);

myRowItem2 = myDataTable2.NewRow();
myRowItem2["ID"] = 3;
myRowItem2["theTime"] = "yet_more time";
myRowItem2["machine_state"] = "yet_Another_State";
myDataTable2.Rows.Add(myRowItem2);

dataGrid1 = new DataGrid();
dataGrid1.DataSource = myDataTable2;

Sorry bout the poor formatting ... when I debug and scroll through the
watch window it certainly appears that myDataTable2 exists and is populated
... datagrid1 doesn't seem to believe so. I dropped the datagrid in with
using VS2003 IDE .. so all the windows form designer code is untouched ...
and it certainly displays the blank DataGrid when I execute ... just not
populated.

regards and tnx for any guidance Bob.
Feb 14 '06 #1
1 1102
bob
OK ... so there are some trees there in that forest ... I'll take my foot
out of my mouth now.

I figured it out ... went bit mad declaring things ... redeclared the
datagrid1 control ...
Feb 14 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by pei_world | last post: by
8 posts views Thread by Inigo Jimenez | last post: by
1 post views Thread by Michelle Stone | last post: by
2 posts views Thread by Marty McDonald | last post: by
reply views Thread by BK Kim | last post: by
5 posts views Thread by tshad | last post: by
reply views Thread by Familjen Karlsson | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.