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

B

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.
 
B

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 ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top