This is a migrated thread and some comments may be shown as answers.

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

2 Answers 64 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Tajes
Top achievements
Rank 1
Tajes asked on 05 Nov 2010, 11:52 AM
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 Answers, 1 is accepted

Sort by
0
Tajes
Top achievements
Rank 1
answered on 08 Nov 2010, 04:07 PM
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.
0
Accepted
Petko_I
Telerik team
answered on 10 Nov 2010, 05:09 PM
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.

Regards,
Petko_I
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
Tags
Getting Started
Asked by
Tajes
Top achievements
Rank 1
Answers by
Tajes
Top achievements
Rank 1
Petko_I
Telerik team
Share this question
or