Showing data from related objects in Windows Forms

Thread is closed for posting
2 posts, 0 answers
  1. John
    John avatar
    2 posts
    Member since:
    Jun 2009

    Posted 07 Aug 2009 Link to this post

    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 ( to have both a Person and a PersonID property.

    Customer has the following properties:


    Person has the following properties:

    ... 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?
  2. Alexander
    Alexander avatar
    727 posts

    Posted 12 Aug 2009 Link to this post

    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.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,
    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.
Back to Top