Home Forums WinForms controls Xceed Grid for WinForms Master/Detail Issue Reply To: Master/Detail Issue

Xceed Support
Member
Post count: 5658

I ran the following code (trying to reproduce the issue), but did not get any error. The relation between the table was set and I was able to see the Master/Detail grid without any problem:

<code>
DataSet dataSet = new DataSet();
DataTable dataTable1 = new DataTable();
DataTable dataTable2 = new DataTable();

dataTable1.Columns.Add( new DataColumn( “PK”, typeof( int ) ) );
dataTable1.Columns.Add( new DataColumn( “Bla”, typeof( string ) ) );

dataTable2.Columns.Add( new DataColumn( “FK”, typeof( int ) ) );
dataTable2.Columns.Add( new DataColumn( “Bla”, typeof( string ) ) );

for( int i = 0; i < 5; i++ )
{
System.Data.DataRow dataRow;

dataRow = dataTable1.NewRow();

dataRow[ 0 ] = i;
dataRow[ 1 ] = “main bla ” + i.ToString();

dataTable1.Rows.Add( dataRow );

for( int j = 0; j < 10; j++ )
{
System.Data.DataRow subDataRow;

subDataRow = dataTable2.NewRow();
subDataRow[ 0 ] = i;
subDataRow[ 1 ] = “sub bla ” + j.ToString();

dataTable2.Rows.Add( subDataRow );
}
}

dataSet.Tables.Add( dataTable1 );
dataSet.Tables.Add( dataTable2 );

dataSet.Relations.Add( new DataRelation( “Relation1”, dataTable1.Columns[ “PK” ], dataTable2.Columns[ “FK” ] ) );

gridControl1.BeginInit();

gridControl1.SetDataBinding( dataTable1, string.Empty );

DetailGrid detailGridTemplate = new DetailGrid();
detailGridTemplate.SetDataBinding( dataTable1, “Relation1” );

gridControl1.DetailGridTemplates.Add( detailGridTemplate );

gridControl1.UpdateDetailGrids();

gridControl1.EndInit();

</code>

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