Link to home
Start Free TrialLog in
Avatar of CodeDeamon
CodeDeamon

asked on

Can't Create a child list for field

I want to programmatically create a datatable and bind it to a datagrid.  I have created a test function to fill a datatable (this will change once I get it working):
private static DataTable GetDataTable(string[] strArr)
            {
                  DataTable dt = new DataTable();

                  dt.Columns.Add("First Name", typeof(string));
                  dt.Columns.Add("Last Name", typeof(string));
                  dt.Columns.Add("Position", typeof(string));
                                    
                  dt.Rows.Add(new Object[] {"Theodore", "Roosevelt", "President" });
                  dt.Rows.Add(new Object[] {"Winston",  "Churchill", "Prime Minister" });
                  dt.Rows.Add(new Object[] {"Pablo",    "Picasso",  "Artist"  });
                  dt.Rows.Add(new Object[] {"Charlie",  "Chaplin",  "Actor"  });
                  dt.Rows.Add(new Object[] {"Steven",   "Spielberg", "Director" });
                  dt.Rows.Add(new Object[] {"Bart",     "Simpson",   "Cartoon Character" });

                  return dt;
            }

I then try to bind it to a datagrid to be shown on my form:

try
                  {
                        DataTable dt = GetDataTable(strFrame);

                        DataGrid dg = new DataGrid();
                  
                        dg.SetDataBinding(dt, "Data");

                        groupArea.Controls.Add(dg);
                  }
                  catch(Exception ex)
                  {
                        MessageBox.Show(ex.Message);
                        return;
                  }

It throws the following exception: "Can't Create a child list for field data".  Any ideas?
ASKER CERTIFIED SOLUTION
Avatar of esteban_felipe
esteban_felipe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CodeDeamon
CodeDeamon

ASKER

Excellent!  Brief explanation as to why that worked?