Home Forums WinForms controls Xceed Grid for WinForms Xceed Grid for .Net – child rows border aren’t displayed corectly.

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

    Hello,

    Starting from another example that was posted on xceed forums I’ve made an example using XceedGrid for .Net. The examples contains 2 DetailGrid’s in order to display data on 2 levels. The problem is that when running this example some parts of the rows borders aren’t displayed. Another problem would be that when using vertical scrolling the horizontal scroll sometimes began to appear&disapper. How can i fix this?

    <code>

     

     private void Form1_Load(object sender, EventArgs e)
            {
                for (int j = 0; j < 4; j++)
                {
                    Column col = new Column(“Column” + j.ToString());
                    col.Width = 100;
                    gridControl1.Columns.Add(col);
                }

                for (int i = 0; i < 5; i++)
                {
                    Xceed.Grid.DataRow row = gridControl1.DataRows.AddNew();
                    foreach (Cell cell in row.Cells)
                    {
                        cell.Value = “Item ” + i.ToString();
                    }
                    row.EndEdit();
                }

                DetailGrid myDetail = new DetailGrid();
                myDetail.TopMargin.Height = 0;
                myDetail.BottomMargin.Height = 0;
                ColumnManagerRow cmr = new ColumnManagerRow();
                cmr.Visible = false;
                myDetail.HeaderRows.Add(cmr);
                gridControl1.DetailGridTemplates.Add(myDetail);
                gridControl1.SynchronizeDetailGrids = false;
                gridControl1.InitializingDetailGrid += new InitializingDetailGridEventHandler(gridControl1_InitializingDetailGrid);
                gridControl1.UpdateDetailGrids();
            }

            void gridControl1_InitializingDetailGrid(object sender, InitializingDetailGridEventArgs e)
            {
                for (int j = 0; j < e.Grid.ParentDataRow.Index + 1; j++)
                {
                    Column col = new Column(“SubColumn” + j.ToString());
                    e.Grid.Columns.Add(col);
                }

                for (int i = 0; i < 5; i++)
                {
                    Xceed.Grid.DataRow row = e.Grid.DataRows.AddNew();
                    foreach (Cell cell in row.Cells)
                    {
                        cell.Value = “SubItem ” + i.ToString();
                    }
                    row.EndEdit();
                }

                DetailGrid myDetail2 = new DetailGrid();
                myDetail2.TopMargin.Height = 0;
                myDetail2.BottomMargin.Height = 0;
                ColumnManagerRow cmr2 = new ColumnManagerRow();
                cmr2.Visible = false;
                myDetail2.HeaderRows.Add(cmr2);
                e.Grid.DetailGridTemplates.Add(myDetail2);
                e.Grid.InitializingDetailGrid += new InitializingDetailGridEventHandler(Grid_InitializingDetailGrid);
                e.Grid.UpdateDetailGrids();
            }

            void Grid_InitializingDetailGrid(object sender, InitializingDetailGridEventArgs e)
            {
                for (int j = 0; j < e.Grid.ParentDataRow.Index + 1; j++)
                {
                    Column col = new Column(“Sub2Column” + j.ToString());
                    e.Grid.Columns.Add(col);
                }

                for (int i = 0; i < 5; i++)
                {
                    Xceed.Grid.DataRow row = e.Grid.DataRows.AddNew();
                    foreach (Cell cell in row.Cells)
                    {
                        cell.Value = “Sub2Item ” + i.ToString();
                    }
                    row.EndEdit();
                }
            }

     

    </code>

     

    Best regards!

    Imported from legacy forums. Posted by Mihai (had 1244 views)

    User (Old forums)
    Member
    Post count: 23064

    I haven’t try your code, nor have I tried to re-work it, but one thing you need is first setup the grids in the form load event, and add rows only after this is done.  The reason is that the DetailGridTemplates property that you set in the first InitializingDetailGrid event is, as its name implies, a template, and you constantly change it (every time the event is triggered), and then update the whole grid with it when calling UpdateDetailGrids().

    So set up the grid and both detail grids only once in form_load, including the subscribing to both InitializingDetailGrid events, then add rows to the main grid.  This will trigger the first InitializingDetailGrid event, in which you can still add your columns and use e.Grid to add rows to this detail grid.  In turn, this will trigger the second InitializingDetailGrid event, again in which you add columns and  rows for that detail grid.

    One more thing. If you set the ColumnManagerRow visible property to false, and to not change it later in your application, you don’t need to create and add one to the detail grids.

     

    Imported from legacy forums. Posted by André (had 351 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks for your reply Andre!

       I’ve made the changes that you suggest but the problem persists: the row right corner upper border of the childRows doesn’t appear. If i remove the myDetail.TopMargin.Height = 0;myDetail.BottomMargin.Height = 0 (for both detailGrid) from my code then all it’s ok. But i need those settings.

       I’ve simplified the example so now each detailsGrid and the main grid contains 2 columns: Name and Value. Another question that i have is:

        – How can i make that the value column to be allways (for the main grid and also for both detailsGrid) right aligned with the parent row Value Column. (i’m setting the width of each child Value column to the same value with it’s parent Value column width but for each child level it gets “delayed” with the length of the TreeViewLine between the parent and the child row). How can I know this TreeViewLine width? (so i can campute the width of the Name column to be smaller with this size).

     

    <code>

     private void Form1_Load(object sender, EventArgs e)
            {
                this.gridControl1.BeginInit();

                this.groupByRow1.Visible = false;
                gridControl1.SynchronizeDetailGrids = false;

                // Add first GridTemplate.
                DetailGrid myDetail = new DetailGrid();
                myDetail.TopMargin.Height = 0;
                myDetail.BottomMargin.Height = 0;
                gridControl1.DetailGridTemplates.Add(myDetail);
                gridControl1.InitializingDetailGrid += new InitializingDetailGridEventHandler(gridControl1_InitializingDetailGrid);

                // Add second GridTemplate.
                DetailGrid myDetail2 = new DetailGrid();
                myDetail2.TopMargin.Height = 0;
                myDetail2.BottomMargin.Height = 0;
                gridControl1.DetailGridTemplates[0].DetailGridTemplates.Add(myDetail2);
                gridControl1.DetailGridTemplates[0].InitializingDetailGrid += new InitializingDetailGridEventHandler(Grid_InitializingDetailGrid);

                gridControl1.UpdateDetailGrids();
                gridControl1.EndInit();

                // Add columns.
                Column colName = new Column(“Name”);
                colName.Width = 200;
                gridControl1.Columns.Add(colName);

                Column colValue = new Column(“Value”);
                colValue.Width = 200;
                gridControl1.Columns.Add(colValue);

                // Add rows.
                for (int i = 0; i < 3; i++)
                {
                    Xceed.Grid.DataRow row = gridControl1.DataRows.AddNew();
                    row.Cells[“Name”].Value = “ParentName” + i.ToString();
                    row.Cells[“Value”].Value = “ParentValue” + i.ToString();
                    row.EndEdit();
                }
            }

            void gridControl1_InitializingDetailGrid(object sender, InitializingDetailGridEventArgs e)
            {
                Column colChildName = new Column(“ChildName”);
                colChildName.Width = 200;
                e.Grid.Columns.Add(colChildName);

                Column colChildValue = new Column(“ChildValue”);
                colChildValue.Width = 200;
                e.Grid.Columns.Add(colChildValue);

                for (int i = 0; i < 3; i++)
                {
                    Xceed.Grid.DataRow row = e.Grid.DataRows.AddNew();
                    row.Cells[“ChildName”].Value = “ChildName” + i.ToString();
                    row.Cells[“ChildValue”].Value = “ChildValue” + i.ToString();
                    row.EndEdit();
                }
            }

            void Grid_InitializingDetailGrid(object sender, InitializingDetailGridEventArgs e)
            {
                Column colChildName2nd = new Column(“ChildName2nd”);
                colChildName2nd.Width = 200;
                e.Grid.Columns.Add(colChildName2nd);

                Column colChildValue2nd = new Column(“ChildValue2nd”);
                colChildValue2nd.Width = 200;
                e.Grid.Columns.Add(colChildValue2nd);

                for (int i = 0; i < 3; i++)
                {
                    Xceed.Grid.DataRow row = e.Grid.DataRows.AddNew();
                    row.Cells[“ChildName2nd”].Value = “ChildName2nd ” + i.ToString();
                    row.Cells[“ChildValue2nd”].Value = “ChildValue2nd” + i.ToString();
                    row.EndEdit();
                }
            }

    </code>

     

    Best regards!

    Imported from legacy forums. Posted by Mihai (had 443 views)

    User (Old forums)
    Member
    Post count: 23064

    This is not possible, the border has no place to be drawn when it is set to 0.  So you will have to set at least one border to 1 pixel.

    As for the width of the margin of the detail grids, you can use the DetailGrid.SideMargin.Width to retrieve it.

    e.g. :

    colChildValue.Width = 200 – e.Grid.SideMargin.Width;

    and

    colChildValue2nd.Width = 200 – e.Grid.SideMargin.Width – e.Grid.ParentGrid.SideMargin.Width;

    for the second detail grid.

     

    Imported from legacy forums. Posted by André (had 1819 views)

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