Home Forums WinForms controls Xceed Grid for WinForms Multi Level Grid with Relations

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #17716 |

    Hi

    I used the code from the following example and extended it to have another level

    http://xceed.com/CS/forums/thread/30643.aspx

    however it will not work

    can anyone spot if i have done something wrong or is it indeed possible?

    it’s driving me nuts

                gridControl1.SynchronizeDetailGrids = true;
                System.Data.DataTable dSource = new System.Data.DataTable(“Shows”);

                dSource.Columns.Add(“ID”, typeof(int));
                dSource.Columns.Add(“TV Show”, typeof(string));
                dSource.Columns.Add(“TV Station”, typeof(string));

                System.Data.DataRow dRow = dSource.NewRow();
                dRow[0] = 0;
                dRow[1] = “Family Guy”;
                dRow[2] = “Fox”;
                dSource.Rows.Add(dRow);

                dRow = dSource.NewRow();
                dRow[0] = 1;
                dRow[1] = “The Simpsons”;
                dRow[2] = “Fox”;
                dSource.Rows.Add(dRow);

                dRow = dSource.NewRow();
                dRow[0] = 2;
                dRow[1] = “Futurama”;
                dRow[2] = “Fox”;
                dSource.Rows.Add(dRow);

                dRow = dSource.NewRow();
                dRow[0] = 3;
                dRow[1] = “Beavis & Butthead”;
                dRow[2] = “MTV”;
                dSource.Rows.Add(dRow);

                #endregion Create Master DataTable / Fill Master DataTable

                #region Create Detail DataTable / Fill Detail DataTable

                System.Data.DataTable dDetail = new System.Data.DataTable(“Detail”);

                dDetail.Columns.Add(“ID”, typeof(int));
                dDetail.Columns.Add(“Name”, typeof(string));
                dDetail.Columns.Add(“Occupation”, typeof(string));
                dDetail.Columns.Add(“ID2”, typeof(int));

                dRow = dDetail.NewRow();
                dRow[0] = 0;
                dRow[1] = “Peter”;
                dRow[2] = “Toy Factory worker”;
                dRow[3] = 1;
                dDetail.Rows.Add(dRow);

                dRow = dDetail.NewRow();
                dRow[0] = 0;
                dRow[1] = “Lois”;
                dRow[2] = “Housekeeper”;
                dRow[3] = 2;
                dDetail.Rows.Add(dRow);

                dRow = dDetail.NewRow();
                dRow[0] = 0;
                dRow[1] = “Chris”;
                dRow[2] = “Student”;
                dRow[3] = 3;
                dDetail.Rows.Add(dRow);

                dRow = dDetail.NewRow();
                dRow[0] = 0;
                dRow[1] = “Meg”;
                dRow[2] = “Student”;
                dRow[3] = 4;
                dDetail.Rows.Add(dRow);

                dRow = dDetail.NewRow();
                dRow[0] = 0;
                dRow[1] = “Stewie”;
                dRow[2] = “Baby”;
                dRow[3] = 5;
                dDetail.Rows.Add(dRow);

                dRow = dDetail.NewRow();
                dRow[0] = 0;
                dRow[1] = “Brian”;
                dRow[2] = “Dog”;
                dRow[3] = 6;
                dDetail.Rows.Add(dRow);

                dRow = dDetail.NewRow();
                dRow[0] = 1;
                dRow[1] = “Homer”;
                dRow[2] = “Nuclear Plant Worker”;
                dRow[3] = 7;
                dDetail.Rows.Add(dRow);

                dRow = dDetail.NewRow();
                dRow[0] = 1;
                dRow[1] = “Marge”;
                dRow[2] = “Housekeeper”;
                dRow[3] = 8;
                dDetail.Rows.Add(dRow);

                dRow = dDetail.NewRow();
                dRow[0] = 1;
                dRow[1] = “Lisa”;
                dRow[2] = “Student”;
                dRow[3] = 9;
                dDetail.Rows.Add(dRow);

                dRow = dDetail.NewRow();
                dRow[0] = 1;
                dRow[1] = “Bart”;
                dRow[2] = “Student”;
                dRow[3] = 10;
                dDetail.Rows.Add(dRow);

                dRow = dDetail.NewRow();
                dRow[0] = 1;
                dRow[1] = “Maggie”;
                dRow[2] = “Baby”;
                dRow[3] = 11;
                dDetail.Rows.Add(dRow);

                dRow = dDetail.NewRow();
                dRow[0] = 2;
                dRow[1] = “Fry”;
                dRow[2] = “Pizza delivery boy”;
                dRow[3] = 12;
                dDetail.Rows.Add(dRow);

                dRow = dDetail.NewRow();
                dRow[0] = 2;
                dRow[1] = “Lila”;
                dRow[2] = “Spaceship captain”;
                dRow[3] = 13;
                dDetail.Rows.Add(dRow);

                dRow = dDetail.NewRow();
                dRow[0] = 2;
                dRow[1] = “Bender”;
                dRow[2] = “Alcoholic Robot”;
                dRow[3] = 14;
                dDetail.Rows.Add(dRow);

                dRow = dDetail.NewRow();
                dRow[0] = 3;
                dRow[1] = “Beavis”;
                dRow[2] = “Retard”;
                dRow[3] = 15;
                dDetail.Rows.Add(dRow);

                dRow = dDetail.NewRow();
                dRow[0] = 3;
                dRow[1] = “Butthead”;
                dRow[2] = “Retard”;
                dRow[3] = 16;
                dDetail.Rows.Add(dRow);

                #endregion Create Detail DataTable / Fill Detail DataTable

                #region Create Detail DataTable / Fill Detail DataTable

                System.Data.DataTable dDetail2 = new System.Data.DataTable(“Detail2”);

                dDetail2.Columns.Add(“ID”, typeof(int));
                dDetail2.Columns.Add(“Name”, typeof(string));

                dRow = dDetail2.NewRow();
                dRow[0] = 2;
                dRow[1] = “TEST TEST”;
                dDetail2.Rows.Add(dRow);

                #region Create DataSet / Add the Tables to it / Create Relation

                DataSet myData = new DataSet();

                myData.Tables.Add(dSource);
                myData.Tables.Add(dDetail);
                myData.Tables.Add(dDetail2);

                DataRelation myRelation = new DataRelation(“Show-VS-Characters”, dSource.Columns[“ID”], dDetail.Columns[“ID”], false);
                DataRelation myRelation2 = new DataRelation(“sub1”, dDetail.Columns[“ID2”], dDetail2.Columns[“ID”], false);

                myData.Relations.Add(myRelation);
                myData.Relations.Add(myRelation2);

                #endregion Create DataSet / Add the Tables to it / Create Relation

                #region Bind main grid Control to the Master table

                gridControl1.SetDataBinding(myData, myData.Tables[“Shows”].TableName);

                #endregion Bind main grid Control to the Master table

                #region Create detail Grid / Bind to relation

                DetailGrid detailGrid1 = new DetailGrid();
                detailGrid1.SetDataBinding(myData, “Shows.” + myData.Relations[0].RelationName);
                detailGrid1.HeaderRows.Add(new Xceed.Grid.ColumnManagerRow());
                gridControl1.DetailGridTemplates.Add(detailGrid1);

                #endregion Create detail Grid / Bind to relation

                DetailGrid detailGrid2 = new DetailGrid();
                detailGrid2.SetDataBinding(myData, “Detail.” + myData.Relations[1].RelationName);
                detailGrid2.HeaderRows.Add(new Xceed.Grid.ColumnManagerRow());
                detailGrid1.DetailGridTemplates.Add(detailGrid2);

                #endregion Create detail Grid / Bind to relation

                gridControl1.DetailGridTemplates[0].Columns[“ID”].Visible = false;
                gridControl1.DetailGridTemplates[0].Columns[“Occupation”].Width = 300;

                gridControl1.UpdateDetailGrids();

    Imported from legacy forums. Posted by Peter (had 1338 views)

    Diane [Xceed]
    Moderator
    Post count: 1353

    This issue was resolved through email support, but in order to benefit others, the solution was to refer to the Master/Detail sample that we include with our installation package.

     

    Imported from legacy forums. Posted by Diane [Xceed] (had 897 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.