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

Hierarchy Gridview Relation Problem

5 Answers 163 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ryda
Top achievements
Rank 1
Ryda asked on 31 Jul 2014, 10:49 AM
Hello, 

I use OS: Win 8.1
         .Net4.5
        UI fo Winforms Vers. 2014.2 715 

I try to make a relation between 2 tables in my MS Entity (Framework 6.0.1),

The problem is the tables don't have a column in common so that i can make a direct relation,

What i need is a possibility to .Join a third table to my parent which provides the missing column.

My 3 tables are

tbl_AffiliateCommision which should be my parent template in the Hierarchygridview this table provides me the column "AffiliateUser" and the grouping would be done with this column.

tbl_Affiliate in this table every AffiliateUser gets his specific "IdAffiliates". This table would provide both columns. This table should not be shown in the grid

ItemAffiliate which should be the child template and  provides me the sold items and the column "IdAffiliate" which is a undergroup of the Column "AffiliateUser" ( AffiliateUser is not available in this table)

e.g.: AffiliateUser : 12354 has the IdAffiliates: 1,4,6
         AffiliateUser: 32145 has the IdAffiliates: 2,3,7

Here some code for better a understanding 

in the 01 line i just look up the data i would use the same Join in teh 02 line if it would work like this. 
the rest of the code shows how i would make my grid.

Please let me know if i forgot to give you important information.

01.var g = db.tbl_wat_Affiliate_Commission.Join(db.tbl_wat_Affiliate, ac => ac.IdAffiliateUser, a => a.AffiliateUser, (ac, a) => new { ac, a });
02.this.radGridView1.DataSource = db.tbl_wat_Affiliate_Commission.Local.ToBindingList();
03.this.radGridView1.AllowAddNewRow = true;
04.this.radGridView1.AllowEditRow = true;
05.this.radGridView1.AllowDeleteRow = true;
06. 
07.// Create and load child
08. 
09. db.tbl_sst_ItemAffiliate.Load();
10. 
11.GridViewTemplate template = new GridViewTemplate();
12.template.DataSource = db.tbl_sst_ItemAffiliate.Local.ToBindingList();
13.// Hinzufügen des childtemps.//
14.this.radGridView1.MasterTemplate.Templates.Add(template);
15. 
16.//Create relation//
17.GridViewRelation relation = new GridViewRelation(this.radGridView1.MasterTemplate);
18.relation.ChildTemplate = template;
19.relation.RelationName = "Affiliate";
20.relation.ParentColumnNames.Add("IdAffiliateUser");
21.relation.ChildColumnNames.Add("IdAffiliateUser");
22.this.radGridView1.Relations.Add(relation);


best regards 

5 Answers, 1 is accepted

Sort by
0
George
Telerik team
answered on 05 Aug 2014, 07:52 AM
Hello Ryda,

Thank you for contacting Telerik Support.

As far as I can tell from the provided information, you have three tables: оne which has some name, one which has Ids and one which has info about sold items and the ids from the second table. With this setup it is not possible to make a relation without having a common property between the child template and the master template. You will need to somehow join the first and second tables into a common collection which will be the master template of RadGridView. After that you can create a proper relation. The concept of joining tables requires you to have a common key. One way here is to redesign your database in order to enable this option. Another option is to perform a pure linq query based on some conditions. For example, as in the following StackOverflow post: Join two related tables into a single entity using Entity Framework - Stack Overflow.

I hope this helps. Do not hesitate to let me know, should you have further questions.

Regards,
George
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Ryda
Top achievements
Rank 1
answered on 05 Aug 2014, 12:20 PM
Hello George,

I solved the problem with a class(model in MVC) in which I defined every column.
After every column was defined i made a pure linq query  in which i joined the 2 tables and filled my model with this data.

Everything else is a problem with the data preparation. 

Thank you for your help.

0
George
Telerik team
answered on 06 Aug 2014, 02:03 PM
Hello Ryda,

I am glad that you were able to resolve the problem at hand and that I was of help.

Do not hesitate to let us know, should you have further questions.

Regards,
George
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Ryda
Top achievements
Rank 1
answered on 09 Sep 2014, 07:36 AM
Hello,

I have another problem.

I want to display a model like this.

public class NewsletterOfferPlanungModel
{
    public NewsletterOfferPlanungModel()
    {
        this.etNewsletterOffer = new EtNewsletterOffer();
        this.etNewsletter = new EtNewsletter();
         
    }
 
    public Int32 nlCount { get; set; }
 
    //tbl_Offer
    public Byte Nächte { get; set; }
    public String IdVerpflegung { get; set; }
 
    //tbl_OfferProperty
    public Int16? IdSellingtype { get; set; }
 
    public EtNewsletterOffer etNewsletterOffer { get; set; }
    public EtNewsletter etNewsletter { get; set; }
 
}

in a 2 level hierarchy.

But as it comes to the grid only the first level will be shown in the grid (the arrow for expand is there but it just don't drop down )
The navigationproperty for the relation is "idNewsletter" 

I made a relation like this. with and without the "etNewsletter." /"etNewsletterOffer."

GridViewRelation relation = new GridViewRelation(this.radGridView1.MasterTemplate);
relation.ChildTemplate = this.radGridView1.MasterTemplate.Templates[0];
relation.RelationName = "IdNewsletter";
relation.ChildColumnNames.Add("etNewsletterOffer.IdNewsletter");
relation.ParentColumnNames.Add("etNewsletter.IdNewsletter");
this.radGridView1.Relations.Add(relation);

I create every column by hand in a extra class which decides by case which format the Column should get 

e.g.
        public static void SetColEtNewsletterOfferChildgrid(GridViewTemplate trGV, Int16 zeilen = 1)
        {
            trGV.Columns.Clear();
            trGV.Columns.AddRange(new GridViewDataColumn[] {
//fyi i call the SetColumn() like this ("FIELDTYPE", "FIELDNAME","DISPLAYNAME","SPECIAL DISPLAY PROPERTY ", "Width")
            SetColumn(Fields.Id, "etNewsletterOffer.Sort", "Sort", false,40),
            SetColumn(Fields.IdPlatform, "etNewsletterOffer.IdPlatform", "Plattf.", true, 35),
            SetColumn(Fields.TrueFalse,"etNewsletterOffer.Deal","Deal", false, 50),
            SetColumn(Fields.TrueFalse,"etNewsletterOffer.NewOffer","Neu", false, 50),
            SetColumn(Fields.IdContact, "etNewsletterOffer.IdSstOfferContact", "Hotel", false, 100),
            SetColumn(Fields.Id, "etNewsletterOffer.IdSstOffer", "IdAngebot", true, 100),
            SetColumn(Fields.Id,"Nächte","Nä", false, 50),
            SetColumn(Fields.Text,"IdVerpflegung","Verpf.", true, 50),
            SetColumn(Fields.IdSellingType,"IdSellingType","Typ", false, 50),
            SetColumn(Fields.Datum, "etNewsletterOffer.ReadyForSendOffer", "Angebot fertig",true,90),
            SetColumn(Fields.IdEmployee, "etNewsletterOffer.RfsUserOffer", "Ersteller",true,50),
            SetColumn(Fields.Id, "nlCount", "Anzahl",true,80),
            SetColumn(Fields.Text,"etNewsletterOffer.OfferDescription","Angebot Beschreibung", true, 200)
            });
            trGV.AllowAutoSizeColumns = true;
            trGV.AllowAddNewRow = true;
            trGV.AllowEditRow = true;
            trGV.AllowDeleteRow = true;
            trGV.AllowRowReorder = true;
            trGV.ReadOnly = false;
            trGV.AutoGenerateColumns = true;
            trGV.EnableSorting = true;
            trGV.SortDescriptors.Expression = "Sort ASC";
 
            trGV.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
        }


Regards,
Ryda
0
George
Telerik team
answered on 11 Sep 2014, 02:57 PM
Hello Ryda,

Thank you for your reply.

I cannot understand how you are creating the columns and what properties are being assigned to them from your code, thus I cannot give you any definitive answer. I would recommend reading the Binding to Hierarchical Data Programmatically article in order to get the idea behind hierarchical binding and possibly see any mistakes that you might have made.

If this does not help, please try to setup a sample project for me where the problem is reproducible. If that is not possible, try to provide me with as much code as possible so that I have enough information to investigate the matter.

Let me know, should you require further assistance.

Regards,
George
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
Ryda
Top achievements
Rank 1
Answers by
George
Telerik team
Ryda
Top achievements
Rank 1
Share this question
or