Parent/Child Grid(hierarchy)

5 posts, 0 answers
  1. Anthony
    Anthony avatar
    24 posts
    Member since:
    Oct 2013

    Posted 23 Nov 2013 Link to this post

    Hi Everyone,

    I'm looking for this exact Example but for Windows Forms solution. Anyone have a sample or know where I can find it? 

    Thank you,
    Anthony
  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3945 posts

    Posted 27 Nov 2013 Link to this post

    Hello Anthony,

    Thank you for contacting Telerik Support.

    Please find attached a sample project, demonstrating how to implement related grids. The first grid is bound to the Customers table from the Northwind database. The second shows the orders for the selected customer from the first grid.

    I hope this information helps. Should you have further questions, I would be glad to help.

    Regards,
    Desislava
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. Anthony
    Anthony avatar
    24 posts
    Member since:
    Oct 2013

    Posted 27 Nov 2013 Link to this post

    Dear Desislava,

    I have a quick question, I notice that the your function "ExtractOrders"  is just hiding columns that doesn't match  the CustomerID.  This might work for viewing purposes but what if you need to work with the rows in the gridview?  Like loop through all of them and grab the cell values?  

    Prior to your  solution.  I came up with a solution of my own. I created a DataSet of the Northwind Orders and OrderDetails(add a query to accept OrderID parameter call "GetDataByOrderID"). I load the two grid from behind code using the initial(first) row OrderID to populate the OrderDetail GridView.  I then add a SelectionChanged event to auto populate the Order Details only for the selected OrderID.  Below is the behind code for my solution.  I feel that this will provide a more accurate data.  I could be wrong because I'm new in programming.
    private void OrderDetails_Load(object sender, EventArgs e)
            {
                int OrderID = 0;
                OrderID = Convert.ToInt32(radGridView1.SelectedRows[0].Cells[0].Value); //Select by Cell Unique Index
                var dbdata = new NORTHWNDDataSetTableAdapters.OrdersTableAdapter();
                var dbdata2 = new NORTHWNDDataSetTableAdapters.OrderDetails2TableAdapter();
     
                radGridView1.DataSource = dbdata.GetData();
                radGridView2.DataSource = dbdata2.GetDataByOrderID(OrderID);
                radGridView1.MasterTemplate.AutoSizeColumnsMode =  GridViewAutoSizeColumnsMode.Fill;
                radGridView2.MasterTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
     
     
            }
     
            private void radGridView1_SelectionChanged(object sender, EventArgs e)
            {
                int OrderID = 0;
                if (radGridView1.SelectedRows.Count > 0)
                {
                    //string CustomerID = radGridView1.SelectedRows[0].Cells["OrderID"].Value.ToString(); //Select by Cell Unique Name
                    OrderID = Convert.ToInt32(radGridView1.SelectedRows[0].Cells[0].Value); //Select by Cell Unique Name
     
                }
                 var dbdata2 = new NORTHWNDDataSetTableAdapters.OrderDetails2TableAdapter();
                radGridView2.DataSource = dbdata2.GetDataByOrderID(OrderID);
                 
            }


  4. Anthony
    Anthony avatar
    24 posts
    Member since:
    Oct 2013

    Posted 27 Nov 2013 Link to this post

    Dear Desislava,

    I took a look at your coding today and enhance it just in case someone maybe look for a similar example.  I even  go one step  further and add the  northwind "OrderDetails".

    1) I add a third radGridView3
    2) Add Parameter query for NorthwindDataSet2 and NorthwindDataSet3
    This is the modification:
    private void Form1_Load(object sender, EventArgs e)
    {
        // TODO: This line of code loads data into the 'nORTHWNDDataSet3.Order_Details' table. You can move, or remove it, as needed.
        this.order_DetailsTableAdapter.Fill(this.nORTHWNDDataSet3.Order_Details);
        // TODO: This line of code loads data into the 'nORTHWNDDataSet2.Orders' table. You can move, or remove it, as needed.
        this.ordersTableAdapter.Fill(this.nORTHWNDDataSet2.Orders);
        // TODO: This line of code loads data into the 'nORTHWNDDataSet1.Customers' table. You can move, or remove it, as needed.
        this.customersTableAdapter.Fill(this.nORTHWNDDataSet1.Customers);
     
    }
     
    private void radGridView1_CurrentRowChanged_1(object sender, CurrentRowChangedEventArgs e)
    {
        DataRowView dataRow = e.CurrentRow.DataBoundItem as DataRowView;
        if (dataRow != null)
        {
            NORTHWNDDataSet1.CustomersRow customerRow = dataRow.Row as NORTHWNDDataSet1.CustomersRow;
            //ExtractOrders(customerRow.CustomerID);
            ordersTableAdapter.FillByCustomerID(this.nORTHWNDDataSet2.Orders, customerRow.CustomerID);
            radGridView2.Refresh();
     
        }
    }
     
     
    private void radGridView2_CurrentRowChanged(object sender, CurrentRowChangedEventArgs e)
    {
        if (radGridView1.SelectedRows.Count > 0)
        {
            DataRowView dataRow = e.CurrentRow.DataBoundItem as DataRowView;
            if (dataRow != null)
            {
                NORTHWNDDataSet2.OrdersRow orderRow = dataRow.Row as NORTHWNDDataSet2.OrdersRow;
                //ExtractOrdersDetails(orderRow.OrderID);
                order_DetailsTableAdapter.FillByOrderID(this.nORTHWNDDataSet3.Order_Details, orderRow.OrderID);
                    radGridView3.Refresh();
            }
        }
    }


  5. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3945 posts

    Posted 02 Dec 2013 Link to this post

    Hello Anthony,

    Thank you for writing back.

    The provided sample project from my previous post just demonstrates the approach for populating the related grids and filtering which rows to be visible. Your note about simply hiding the rows is absolutely correct. This is just a visual illustration of the data. However, when the current parent row is changed, it is necessary to filter which rows to be included in the data source. Our Master/Detail in two grids KB article gives an alternative solution how to display master/detail relation in two grids.

    Please do not hesitate to contact us if you have any additional questions.

    Regards,
    Desislava
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top