EntityCollection bounded to DataGridView : follow the foreign key

Posts   
 
    
kal
User
Posts: 18
Joined: 25-May-2010
# Posted on: 18-Jun-2010 18:57:44   

Hi all,

I have a table A which contains a foreign key F referencing table B : A.F -> B.ID

My Table B contains another field called "Description".

I'm binding an ACollection to a DataGridView. Instead of displaying the ID contained in A.F, I would like to display the Description in table B, following the A.F foreign key.

Is there a proper way to do this, or do I have to build a DataTable by myself ?

Thanks in advance, Kal

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 18-Jun-2010 22:02:54   
David Elizondo | LLBLGen Support Team
kal
User
Posts: 18
Joined: 25-May-2010
# Posted on: 21-Jun-2010 09:32:12   

daelmo wrote:

You have three options. Please check this http://llblgen.com/TinyForum/Messages.aspx?ThreadID=12021&StartAtMessage=0&#66749

Thank you very much for pointing me out the solution I was looking for. Anyway, I found another way of doing this, using dynamic lists : http://www.llblgen.com/documentation/2.6/hh_start.htm#Using%20the%20generated%20code/SelfServicing/Using%20TypedViews,%20TypedLists%20and%20Dynamic%20Lists/gencode_usingdynamiclists.htm

So my code looks like :


            IPredicateExpression filter = new PredicateExpression();
            filter.Add(PARAMETRE_TOP1Fields.Date_Debut >= dateDebutMin);
            filter.AddWithAnd(PARAMETRE_TOP1Fields.Date_Debut <= dateDebutMax);
            filter.AddWithAnd(PARAMETRE_TOP1Fields.Date_Fin <= dateFin);
            filter.AddWithAnd(PARAMETRE_TOP1Fields.ProfilGRD == (string)cbxProfilGRD.SelectedValue);
            filter.AddWithAnd(PARAMETRE_TOP1Fields.Regroupement == (string)cbxGroupement.SelectedValue);
            // Il n'est pas nécessaire de renseigner cbxTypeEngagement ET cbxTypePrix en même temps
            if (cbxTypeEngagement.SelectedIndex != -1)
                filter.AddWithAnd(PARAMETRE_TOP1Fields.Type_Engagement == (int)cbxTypeEngagement.SelectedValue);
            if (cbxTypePrix.SelectedIndex != -1)
                filter.AddWithAnd(PARAMETRE_TOP1Fields.Type_Prix == (int)cbxTypePrix.SelectedValue);


            ResultsetFields fields = new ResultsetFields(7);
            fields.DefineField(PARAMETRE_TOP1Fields.Date_Debut, 0, "Début fourniture");
            fields.DefineField(PARAMETRE_TOP1Fields.Date_Fin, 1, "Fin fourniture");
            fields.DefineField(REGROUPEMENT_ACTIVITEFields.Nom, 2, "Groupement de secteurs d'activité");
            fields.DefineField(PROFIL_GRDFields.Nom, 3, "Profil GRD");
            fields.DefineField(TYPE_ENGAGEMENTFields.Nom, 4, "Type d'engagement");
            fields.DefineField(TYPE_PRIXFields.Nom, 5, "Type de prix");
            fields.DefineField(PARAMETRE_TOP1Fields.Prime_ToP1, 6, "Prime ToP1 (€/MWh)");

            IRelationCollection relations = new RelationCollection();
            relations.Add(PARAMETRE_TOP1Entity.Relations.TYPE_PRIXEntityUsingType_Prix, JoinHint.None);
            relations.Add(PARAMETRE_TOP1Entity.Relations.TYPE_ENGAGEMENTEntityUsingType_Engagement, JoinHint.None);
            relations.Add(PARAMETRE_TOP1Entity.Relations.PROFIL_GRDEntityUsingProfilGRD, JoinHint.None);
            relations.Add(PARAMETRE_TOP1Entity.Relations.REGROUPEMENT_ACTIVITEEntityUsingRegroupement, JoinHint.None);


            DataTable dynamicList = new DataTable();
            TypedListDAO dao = new TypedListDAO();
            dao.GetMultiAsDataTable(fields, dynamicList, 0, null, filter, relations, true, null, null, 0, 0);
            dgvToP1.DataSource = dynamicList;

dgvToP1 is my DataGridView. I'm using Winforms with .NET 2.0.

Cheers!

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 21-Jun-2010 09:53:36   

Thanks for the feedback.