Using a DataRelation with a 2nd DataRelation RRS feed

  • Question

  • Standard example.  Create a DataSet with 2 related tables, define a DataRealtion, and bind them to 2 dataGridViews.  As you walk the first grid view, the 2nd one shows the related rows.

       DataRelation customerDataRelation = new DataRelation("UsefulRelation",


    then display with

     dataGridViewOrderID.DataSource = customerDataSet;
     dataGridViewOrderID.DataMember = "Customers";

                //use data binding with the datagrid view
     orderLinesdataGridView.DataSource = customerDataSet;
     orderLinesdataGridView.DataMember = "Customers.UsefulRelation";

    Works nice.

    Now I want to add a 3rd datagridview, and a second DataRelation, so that the first view shows the customer, the second shows the order, but when I click on one of the orders in the 2nd grid view, the 3rd one shows the order detail.

    So, a table linked to a 2nd table linked to a 3rd table using 2 DataRelations, and then have the datagridviews do the right thing.

    Is this possible?

    with this 2nd DataRelation

     DataRelation productDataRelation = new DataRelation("productDataRelation",

    and this added gui code for the 3rd datagridview

     dataGridViewProductDetail.DataSource = customerDataSet;
     dataGridViewProductDetail.DataMember = "Orders.productDataRelation";

    the 3rd datagridview shows one set of values, but will not update.


    • Edited by kurtfr Tuesday, January 27, 2015 2:14 AM
    Tuesday, January 27, 2015 2:07 AM

All replies

  • the 3rd datagridview shows one set of values, but will not update.

    ... and what do you mean by "will not update"? That's a little ambiguous.

    ~~Bonnie DeWitt [C# MVP]

    Wednesday, January 28, 2015 6:04 AM
  • Be aware that creating the datarelations in your database is preferable and then using a whatever mapper, where you can start with the tableadaptermanager or if you have have an sql server database SQL to Linq or SQL to entities.



    Wednesday, January 28, 2015 6:41 PM