Home Forums WinForms controls Xceed Grid for WinForms How to manually attach a detail grid to a row

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

    Hi Support Team,

    I have seen one of the feature of the grid control is that each row can have its own detail grid. Could you provide some samples of doing this? I tried to do that in the InitializingDetailGrid event; in there I will need to detect the type of the parent row and attach a detail grid to the row depends on its type. However I did not get any luck…

    Regards,
    Dennis

    Imported from legacy forums. Posted by Dennis (had 2479 views)

    Xceed Support
    Member
    Post count: 5658

    Here is an example that shows how you can do that with InitializingDetailGrid event and an unbound grid.

    <code>
    private void Form1_Load( object sender, EventArgs e )
    {
    for( int j = 0; j < 4; j++ )
    {
    Column col = new Column( “Column”+j.ToString() );
    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.HeaderRows.Add( new ColumnManagerRow() );
    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();
    }
    }
    </code>

    Imported from legacy forums. Posted by CharlesB (had 2743 views)

    User (Old forums)
    Member
    Post count: 23064

    Is there any property or something to remove the space between the row and it’s detailsGrid ?

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

    User (Old forums)
    Member
    Post count: 23064

    Insert this line in the Form_Load event :

       myDetail.TopMargin.Height = 0;

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

    User (Old forums)
    Member
    Post count: 23064

    Thanks Andre, it works fine!

     

    Best regards!

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

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