Home Forums WinForms controls Xceed Grid for WinForms DetailGridTemplates and its View

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

    Hi,

    I am creating detail grids at runtime. I have a menu items as add, whenever user selects a row and click on add i will create a detailgrid at runtime and create a row under that.

    Following is my code 

     if (currentDetailGrid.DetailGridTemplates.Count == 0)
             {
                row.ShowPlusMinus = ShowPlusMinus.WhenDetailGridPresent;

                using (DetailGrid preGeneratedNextLevelDetailGrid = new DetailGrid())
                {
                   preGeneratedNextLevelDetailGrid.Collapsed = false;
                   preGeneratedNextLevelDetailGrid.DataRowTemplate.ShowPlusMinus = ShowPlusMinus.Never;
                  

                   currentDetailGrid.DetailGridTemplates.Add(preGeneratedNextLevelDetailGrid);
                   if (currentDetailGrid.Columns.Count == 0)
                   {
                      currentDetailGrid.Columns.Add(new Xceed.Grid.Column(“IName”, typeof(string)));
                      currentDetailGrid.Columns.Add(new Xceed.Grid.Column(“IterationPath”, typeof(string)));
                      currentDetailGrid.Columns.Add(new Xceed.Grid.Column(“StartDate”, typeof(DateTime)));
                      currentDetailGrid.Columns.Add(new Xceed.Grid.Column(“FinishDate”, typeof(DateTime)));
                   }
                   currentDetailGrid.Columns[“IterationPath”].Visible = false;
                   currentDetailGrid.Columns[“IName”].Width = 180;
                   currentDetailGrid.Columns[“FinishDate”].Width = 180;
                   currentDetailGrid.Columns[“StartDate”].Width = 180;
                   Xceed.Grid.DataRow dataRow = currentDetailGrid.DataRows.AddNew();
                   dataRow.Cells[“IName”].Value = String.IsNullOrEmpty(line) ? null : line;
                   dataRow.Cells[“IterationPath”].Value = row.Cells[1].Value;
                   dataRow.Cells[“StartDate”].Value = DateTime.Now;
                   dataRow.Cells[“FinishDate”].Value = DateTime.Now;
                   dataRow.EndEdit();currentDetailGrid.UpdateDetailGrids();

    My issue is when i create these detailGridTempaltes like this i get a space between the rows. How can i avoid this show the datarows without space.

    Sent an email to support@xceed with attachment. Pls help me how do i get rid of this spaces between the rows. 

    Imported from legacy forums. Posted by saumya (had 1842 views)

    Xceed Support
    Member
    Post count: 5658

    Hi Saumya,

    When adding DetailGrids at run-time, it is important to set the DataRelation so that the Grid understands how to place it correctly. The following code demonstrates a “best practice” on how to add DetailGrids at runtime. You will see in the code that the two DataTables are linked by ID which acts as a Foreign Key.

    ————

    #region Create Master DataTable / Fill Master DataTable

          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));

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          dRow = dDetail.NewRow();
          dRow[0] = 3;
          dRow[1] = “Butthead”;
          dRow[2] = “Retard”;
          dDetail.Rows.Add(dRow);
         
          #endregion Create Detail DataTable / Fill Detail DataTable

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

          DataSet myData = new DataSet();

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

          DataRelation myRelation = new DataRelation(“Show-VS-Characters”, dSource.Columns[“ID”] , dDetail.Columns[“ID”], false);
         
          myData.Relations.Add(myRelation);

          #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());

          #endregion Create detail Grid / Bind to relation

          gridControl1.Columns[“ID”].Visible = false;

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

          gridControl1.UpdateDetailGrids();

    ————

    Imported from legacy forums. Posted by Marc [Xceed] (had 1184 views)

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