none
Problem in Binding between parent and child tables RRS feed

  • Question

  • Hi,

    I have two gridview control  like parent gridview like Order table   and child gridview Order_Detail Table . Both are binded to together . If one order is selected from Order table the corresponding order details are shown in the Order_Details table.The question is that I want to insert one record to Order_Details Table without losing the binding.But when i am trying to insert a record, it does not affecting.The datasource is not refreshing.. The code is given below.

    How can i accomplish this? Plz help me...

     

     public partial class MainWindow : Window

        {

            DataClasses1DataContext dc = new DataClasses1DataContext();

            IBindingList l;       

            IBindingList p;     

           public MainWindow()

            {

                InitializeComponent();

                l = dc.Orders.GetNewBindingList();           

                gridControl1.ItemsSource = l;           

            }

            private void Add_Click(object sender, RoutedEventArgs e)

            {

                var source = gridControl2.ItemsSource;            

                System.Data.Linq.EntitySet<Order_Detail> b = (System.Data.Linq.EntitySet<Order_Detail>)source;            

                b.Add(new Order_Detail { OrderID=1,ProductID=1});

                gridControl2.ItemsSource = b;

                gridControl2.RefreshData();//getting error

               // dc.SubmitChanges();      

     }

    }

    Thursday, November 3, 2011 2:19 PM

Answers

All replies

  • Hi,

    I have two gridview control  like parent gridview like Order table   and child gridview Order_Detail Table . Both are binded to together . If one order is selected from Order table the corresponding order details are shown in the Order_Details table.The question is that I want to insert one record to Order_Details Table without losing the binding.But when i am trying to insert a record, it does not affecting.The datasource is not refreshing.. The code is given below.

    How can i accomplish this? Plz help me...

     

     public partial class MainWindow : Window

        {

            DataClasses1DataContext dc = new DataClasses1DataContext();

            IBindingList l;       

            IBindingList p;     

           public MainWindow()

            {

                InitializeComponent();

                l = dc.Orders.GetNewBindingList();           

                gridControl1.ItemsSource = l;           

            }

            private void Add_Click(object sender, RoutedEventArgs e)

            {

                var source = gridControl2.ItemsSource;            

                System.Data.Linq.EntitySet<Order_Detail> b = (System.Data.Linq.EntitySet<Order_Detail>)source;            

                b.Add(new Order_Detail { OrderID=1,ProductID=1});

                gridControl2.ItemsSource = b;

                gridControl2.RefreshData();//getting error

               // dc.SubmitChanges();      

     }

    }

    Thursday, November 3, 2011 2:20 PM
  • Hi,

    You can use ObjectDataSource : http://thedatafarm.com/blog/data-access/using-entity-framework-entities-as-data-sources-in-a-winforms-app/

    http://www.codeproject.com/KB/database/IntroEntityFramework3.aspx

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Monday, November 7, 2011 8:31 AM
    Moderator