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

Showing data from related objects in Windows Forms

1 Answer 57 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.
John
Top achievements
Rank 1
John asked on 07 Aug 2009, 09:28 PM
I'm new to ORM, and I'm guessing that what I'm trying to do is quite simple. I feel quite daft in asking this, but here's the situation....


Let's say we have two object classes: Person and Customer. The CustomerID field is technically a foreign key to the personID. The Customer class has a "Person" property. I have modified it per the directions at (http://www.telerik.com/support/kb/orm/general/direct-access-to-foreign-keys.aspx) to have both a Person and a PersonID property.

Customer has the following properties:

customerid
custComments
isActive
isDeleted
Person
PersonID

Person has the following properties:

id
firstname
lastname
... others such as cellphone, but not necessary to list for this discussion

Now, let's say I want to make a form with a datagrid bound to Customers (not a likely scenario, as the information is limited to the four properties shown above) and underneath that datagrid I want two textboxes bound to the Person.firstname and Person.lastname for the actively selected Customer.... how on earth would I accomplish this? I've tried adding one objectprovider and two objectviews (one with a base class of customer, the other with a base class of person). This sort of works, but the person object provider loads blank records it seems. Can someone point me in the right direction?

1 Answer, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 12 Aug 2009, 07:21 AM
Hello John,

Using one ObjectProvider with an ObjectView should be enough to bind the DataGrid. I assume that the grid is displaying properly the Customers objects. Then you can use the SelectionChanged event of the grid to bind the textboxes:
private void dataGridView1_SelectionChanged(object sender, EventArgs e) 
    Customer c = (Customer) dataGridView1.CurrentRow.DataBoundItem; 
 
    textBox1.DataBindings.Clear(); 
    textBox1.DataBindings.Add(new Binding("Text", c.Person, "FirstName")); 
Note that all changes applied to the objects in the grid and the textboxes are not physically committed to the database until you call objectProvider1.SaveAll();. Hope that helps.

Kind regards,
Alexander
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Getting Started
Asked by
John
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Share this question
or