using System.Data;
using System.Windows;

namespace Ticket219629_DefiningColumnsInChildGrid
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            this.InitializeComponent();

            this.BindDataMainGrid();
        }

        private void BindDataMainGrid()
        {
            DataSet dataSet = this.GetDataSet();
            this.RadGridView1.DataMember = dataSet.Tables["Requests"].TableName;
            this.RadGridView1.ItemsSource = dataSet;
        }

        private DataSet GetDataSet()
        {
            var ds = new DataSet();
            DataTable dtParent;
            dtParent = new DataTable("Requests");
            dtParent.Columns.Add("RequestNumber");
            dtParent.Columns.Add("RequestSum");
            dtParent.Columns.Add("RequestDescription");
            dtParent.Columns.Add("RequestType");
            dtParent.Columns.Add("OrderNumber");
            dtParent.Columns.Add("OrderSum");
            dtParent.Columns.Add("Supplier");
            dtParent.Columns.Add("OrderDescription");
            dtParent.Columns.Add("RequestBalance");

            dtParent.Rows.Add("80710981344", "375", "ABC", "DEF", "81250542", "375", "ABC", "", "0");
            dtParent.Rows.Add("81210981522", "225", "GHI", "JKL", "", "", "", "", "225");

            ds.Tables.Add(dtParent);

            DataTable dtChild;
            dtChild = new DataTable("Details");
            dtChild.Columns.Add("RequestNumber", typeof(string));
            dtChild.Columns.Add("Text", typeof(string));

            dtChild.Rows.Add("80710981344", "111");
            dtChild.Rows.Add("80710981344", "222");
            dtChild.Rows.Add("80710981344", "333");
            dtChild.Rows.Add("81210981522", "444");

            ds.Tables.Add(dtChild);

            ds.Relations.Add("RequestNumber", 
                dtParent.Columns["RequestNumber"], 
                dtChild.Columns["RequestNumber"]);

            return ds;
        }
    }
}
