Home Forums WinForms controls Xceed Grid for WinForms Master/Detail Issue

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

    I have looked at the examples and some other threads posted here and cannot find the answer to my issue. Here is the code:

    clsHelperFunctions.PopulateDatasetTables(cnnSQL, m_customerdDataSet, “RepairsInProcess”, _
    “SELECT * FROM vwInprocess WHERE BusinessUnitID = ” & UserInfo.UserBU)

    clsHelperFunctions.PopulateDatasetTables(cnnSQL, m_customerdDataSet, “AssignedTechs”, _
    “SELECT * FROM vwAssignedTechnicians WHERE BusinessUnitID = ” & UserInfo.UserBU)

    Dim colPrimaryKey(0) As DataColumn
    colPrimaryKey(0) = m_customerdDataSet.Tables(“RepairsInProcess “).Columns(“RO_NBR”)
    m_customerdDataSet.Tables(“RepairsInProcess “).PrimaryKey = colPrimaryKey

    Dim dataRelate As New DataRelation(“RepairsInProcessTechs”, _
    m_customerdDataSet.Tables(0).Columns(“RO_NBR”), _
    m_customerdDataSet.Tables(1).Columns(“RO_NBR”))

    m_customerdDataSet.Relations.Add(dataRelate)

    gcStatus.SetDataBinding(m_customerdDataSet.Tables(“RepairsInProcess “), “”)
    TechGrid.SetDataBinding(m_customerdDataSet.Tables(“RepairsInProcess “), ” RepairsInProcessTechs”)
    gcStatus.EndInit()

    This is the error: The column RepairsInProcessTechs field does not exists in the parent

    Can someone shed some light on this.

    Imported from legacy forums. Posted by Mitchel (had 7202 views)

    User (Old forums)
    Member
    Post count: 23064

    There appears to be a space in the string ” RepairsInProcessTechs”. Try removing it.

    Imported from legacy forums. Posted by Tommy (had 694 views)

    User (Old forums)
    Member
    Post count: 23064

    The space was not there in the code. I copied and pasted from VS to MS Word. The code is 100% correct in VS.

    Imported from legacy forums. Posted by Mitchel (had 405 views)

    User (Old forums)
    Member
    Post count: 23064

    JUst to clear up everything here is the code directly from VS:

    clsHelperFunctions.PopulateDatasetTables(cnnSQL, m_customerdDataSet, “RepairsInProcess”, _
    “SELECT * FROM vwInprocess WHERE BusinessUnitID = ” & UserInfo.UserBU)

    Dim colPrimaryKey(0) As DataColumn
    colPrimaryKey(0) = m_customerdDataSet.Tables(“RepairsInProcess”).Columns(“RO_NBR”)
    m_customerdDataSet.Tables(“RepairsInProcess”).PrimaryKey = colPrimaryKey

    clsHelperFunctions.PopulateDatasetTables(cnnSQL, m_customerdDataSet, “AssignedTechs”, _
    “SELECT * FROM vwAssignedTechnicians WHERE BusinessUnitID = ” & UserInfo.UserBU)

    Dim dataRelate As New DataRelation(“RepairsInProcessTechs”, _
    m_customerdDataSet.Tables(“RepairsInProcess”).Columns(“RO_NBR”), _
    m_customerdDataSet.Tables(“AssignedTechs”).Columns(“RO_NBR”), True)
    m_customerdDataSet.Relations.Add(dataRelate)

    gcStatus.SetDataBinding(m_customerdDataSet.Tables(0), “”)
    gcStatus.SynchronizeDetailGrids = True

    Dim detailTechGrid As New DetailGrid()
    detailTechGrid.SetDataBinding(m_customerdDataSet.Tables(0), “RepairsInProcessTechs”)
    detailTechGrid.HeaderRows.Add(New ColumnManagerRow())
    detailTechGrid.Collapsed = True

    gcStatus.DetailGridTemplates.Add(detailTechGrid)
    gcStatus.UpdateDetailGrids()
    gcStatus.EndInit()

    I have also tried creating a typed dataset and creating the relationship in that dataset and I get the same error as I posted in my original post.

    Imported from legacy forums. Posted by Mitchel (had 330 views)

    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)

    User (Old forums)
    Member
    Post count: 23064

    I have tried using datatables then adding them to the dataset and still get errors. This is the error that I am getting:

    Xceed.Grid.GridException: The Column RepairTechs does not exist in the parent grid.
    at Xceed.Grid.DataManager.BindToDataSource(Object dataSource, String dataMember, Boolean onlyWhenNotSameList, Boolean& dataChanged)
    at Xceed.Grid.DataManager.ForceDataBinding(Object dataSource, String dataMember, Boolean onlyWhenNotSameList, Boolean createDataRows)
    at Xceed.Grid.DetailGrid.OnContainingListChanged(IStructuredList oldContainingList)
    at Xceed.Grid.GroupBase.set_ContainingList(IStructuredList value)
    at Xceed.Grid.Collections.StructuredDetailGridList.OnInsertComplete(Int32 index, Object value)
    at Xceed.Utils.Collections.ListBase.InternalAdd(Object value)
    at Xceed.Grid.Collections.ReadOnlyDetailGridList.InternalAdd(DetailGrid grid)
    at Xceed.Grid.DetailGrid.CreateDetailGrids(DataRow dataRow, Boolean synchronizeDetailGrids)
    at Xceed.Grid.DetailGrid.UpdateDetailGridsOfMySelfAndSyncronizedChild()
    at Xceed.Grid.DetailGrid.DataManager_DataRowsChanged(DataRowsChangedEventArgs e)
    at Xceed.Grid.DataManager.InvokeOnDataRowsChanged(DataRowsChangedEventArgs e)
    at Xceed.Grid.DataManager.CreateDataRows(Boolean forceDataRowsCreation)
    at Xceed.Grid.DataManager.CreateDataRows()
    at Xceed.Grid.DataManager.ReadDataRows()
    at Xceed.Grid.DetailGrid.EndInit()
    at Xceed.Grid.MasterGrid.EndInit()
    at Xceed.Grid.GridControl.EndInit()

    Imported from legacy forums. Posted by Mitchel (had 559 views)

    User (Old forums)
    Member
    Post count: 23064

    Figured it out. You cannot use the AutoCreateColumns property when using detail grids. Which leads to another question, how do you limit your columns without using the AutoCreateColumns property?

    Imported from legacy forums. Posted by Mitchel (had 332 views)

    Xceed Support
    Member
    Post count: 5658

    You can set AutoCreateColumns property (of the master grid) to false even if you have a detail grid. However, you need to add (to the master grid) a DataBoundColumn representing the “Relation” between the master and the detail grid.

    <code>
    gridControl1.AutoCreateColumns = false;

    DataBoundColumn column1 = new DataBoundColumn( “PK” );
    DataBoundColumn column2 = new DataBoundColumn( “Relation1” );

    gridControl1.Columns.Add( column1 );
    gridControl1.Columns.Add( column2 );
    </code>

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

    User (Old forums)
    Member
    Post count: 23064

    It worked perfectly. Thanks everyone for your help.

    Imported from legacy forums. Posted by Mitchel (had 481 views)

    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)

    Xceed Support
    Member
    Post count: 5658

    You need to make sure that the key (identifier) you are using for each parentColumn is unique. For example, you have 3 dataTables: dataTable1, dataTable2, dataTable3. DataTable1 has a unique key column (ID1) and it will be the parentColumn for dataTable2. DataTable2 will have a unique key column (ID2) and the ID1 field can be multiple. Finally, dataTable3 will have a ID2 column with non-unique value.

    Here is a diagram to illustrate this point:

    <code>
    dataTable1 —> ID1
    |
    |
    dataTable2 —> ID1 ID2
    |
    |
    dataTable3 —>ID2
    </code>

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

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