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

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)