Empty Foreing Key in a relation one to many when I add row in a grid

Thread is closed for posting
3 posts, 1 answers
  1. Tajes
    Tajes avatar
    81 posts
    Member since:
    Sep 2009

    Posted 05 Nov 2010 Link to this post

    Hi anybody,
    I'm trying to create a CRUD Form for two Persistent Classes with a one to many relation (Parent/child relation) created in the DAL and mapped to database. For now I created a form with a bindingSource to manage CRUD operations in parent class and I binded radMaskedTextBox to the differents fields of Parent Class through the bindingsource. I set the bindingsource1.datasource = MyContext.MyParentClass.ToList<MyParentClass>();

            Then, I added a RadDataGrid to manage Child Class:

    BindingSource bs1 = new BindingSource(form.components);
    bs1.DataSource = MyContext.GetAll<MyParentClass>().ToList<MyParentClass>();
    BindingSource bs2 = new BindindSource(form.components);
    bs2.DataSource = bs1;
    bs2.DataMember = "listOfChildrenObjects" //the field of the relation in the parent class
    RadDataGrid grid = new RadData......;
    grid.DataSource = bs2;

          when I move the parent bindingSource, the grid shows me the children objects correctly. My problem is when I try to add a new row  in the grid, the foreing key field in the children object remains empty and also the reference to parent object. It's possible to link the child object to parent object when I add direcctly in the grid or datasource.
          Thanks and sorry for my English.
  2. Tajes
    Tajes avatar
    81 posts
    Member since:
    Sep 2009

    Posted 08 Nov 2010 Link to this post

    I solved the problem. I catch the adding event in the bindinsource and I set the the value of the property of the relation.

    Thanks to everybody.
  3. Answer
    Petko_I avatar
    184 posts

    Posted 10 Nov 2010 Link to this post

    Hello Iván Tajes,

    We are glad you managed to think of a way to build your application. In fact, it is a recommended approach to use the events of the binding source for preparing the data in a state that is suitable for persistence. I would like to use the occasion to mention that with the Q3 release a dedicated SDK browser is introduced for managing sample applications. We have included some samples for a start and their collection will be extended continuously. Do not forget to check them out and see if there is anything of interest that resembles the scenarios you are trying to achieve.

    Should you have any more questions, do not hesitate to contact us right away.

    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top