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

User (Old forums)
Member
Post count: 23064

Can you kindly extend this example to demonstrate one more level of nesting? When I try the following code, I get an ArgumentOutOfRangeException during the gridControl1.EndInit() method – something to do with parameter name ‘index’.

DataSet dataSet = new DataSet();
DataTable dataTable1 = new DataTable();
DataTable dataTable2 = new DataTable();
DataTable dataTable3 = new DataTable();
dataTable1.Columns.Add(new DataColumn(“PK1”, typeof(int)));
dataTable2.Columns.Add(new DataColumn(“FK1”, typeof(int)));
dataTable2.Columns.Add(new DataColumn(“PK2”, typeof(int)));
dataTable3.Columns.Add(new DataColumn(“FK1”, typeof(int)));
dataTable3.Columns.Add(new DataColumn(“FK2”, typeof(int)));
dataTable3.Columns.Add(new DataColumn(“Blah”, typeof(string)));
for (int i = 0; i < 2; i++)
{
System.Data.DataRow dataRow;
dataRow = dataTable1.NewRow();
dataRow[“PK1”] = i;
dataTable1.Rows.Add(dataRow);
for (int j = 0; j < 2; j++)
{
System.Data.DataRow subDataRow;
subDataRow = dataTable2.NewRow();
subDataRow[“FK1”] = i;
subDataRow[“PK2”] = j;
dataTable2.Rows.Add(subDataRow);
for (int k = 0; k < 2; k++)
{
System.Data.DataRow subSubDataRow;
subSubDataRow = dataTable3.NewRow();
subSubDataRow[“FK1”] = i;
subSubDataRow[“FK2”] = j;
subSubDataRow[“Blah”] = string.Format(“value = {0}”, k);
dataTable3.Rows.Add(subSubDataRow);
}
}
}
dataSet.Tables.Add(dataTable1);
dataSet.Tables.Add(dataTable2);
dataSet.Tables.Add(dataTable3);
dataSet.Relations.Add(new DataRelation(“Relation1”, dataTable1.Columns[“PK1”], dataTable2.Columns[“FK1”]));
dataSet.Relations.Add(new DataRelation(“Relation2”,
new DataColumn[] { dataTable2.Columns[“FK1”], dataTable2.Columns[“PK2”] },
new DataColumn[] { dataTable3.Columns[“FK1”], dataTable3.Columns[“FK2”] }));
gridControl1.BeginInit();
gridControl1.SetDataBinding(dataTable1, string.Empty);
DetailGrid detailGridTemplate1 = new DetailGrid();
detailGridTemplate1.SetDataBinding(dataTable1, “Relation1”);
DetailGrid detailGridTemplate2 = new DetailGrid();
detailGridTemplate2.SetDataBinding(dataTable2, “Relation2”);
detailGridTemplate1.DetailGridTemplates.Add(detailGridTemplate2);
detailGridTemplate1.UpdateDetailGrids();
gridControl1.DetailGridTemplates.Add(detailGridTemplate1);
gridControl1.UpdateDetailGrids();
gridControl1.EndInit();

Imported from legacy forums. Posted by ronnotel (had 457 views)