CodeSmith Community
Your Code. Your Way. Faster!

Complex DataGridView

Latest post 10-17-2006 3:11 AM by dreamchaser. 0 replies.
  • 10-17-2006 3:11 AM

    Complex DataGridView

    Hi,

    I'm working with Windows Forms and the new 2.0 databinding functionality. My problem is as follows (simplified):

    On the database level I have 2 tables "Contact" (first name, last name,....) and "Address" (street, nbr, city,....). The Contact table has a foreign key to a record in the Address table. I generated the .netTiers layers, so I have a ContactEntity with a property containing the related AddressEntity.

    public class AddressEntity
    {
         public string Street {get;set;}
         public string City {get;set;}
    ...

    public class ContactEntity
    {
        public string Name {get; set;}
        public AddressEntity Address {get;set;}
    ...
    }

    I want to create a DataGridView containing columns for as well the contact properties as the related address' properties. The DataGridView is connected to a BindingSource, of which the datasource is set to a TList of all Contacts. They are deeploaded, so the address is filled in.

    The problem is that the datagridview columns can only bind to value type properties of Contact itself, like "Name", and not to eg. "Address.Street". Other windows forms controls don't seem to have a problem with binding to "Address.Street".

    For asp.net there seem to be some workarounds on the net, however the only solution I can find for Windows Forms is to create properties in Contact that return those of Address. For instance:

    public class ContactEntity
    {
      .........
      public string Street
      {
         get{ return Address.Street;}
      }
    }

    This works, but I'm asking myself:
    * Is this the only solution? If so, are there some "modified" netTiers or other templates available to generate this in the Entities library? Or are there any plans to provide an option for this in .netTiers in the future?

    I also have another question, concerning performance:
    * How to handle large numbers of records in such a grid. The netTiers way seems to be loading the contacts and then deepload them all to get their addresses (possibly with restrictions to only load the address). This means 1 database query for each contact and isn't very performant. From a database point of view the most performant way would be a select joining the 2 tables, so there is actually only 1 query needed for everything. Are there any ways to let .netTiers correctly fill up a TList of contacts with there addresses by calling just this 1 query?

    tia

    Filed under:
    • Post Points: 5
Page 1 of 1 (1 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems