Search code examples
entity-frameworkdevexpressmaster-detailxtragrid

two level deep master-details for Entity Framework


I am using Entity Framework and DevExpress 10.5 XtraGrid. Imagine that we have entities entity

So my point is to display them in Form using XtraGrids and master-details. The Level tree of gridControl should look like this: enter image description here

So I have implemented events for MainGrid like this

#region gridView1_enents
    private void gridView1_MasterRowEmpty(object sender, DevExpress.XtraGrid.Views.Grid.MasterRowEmptyEventArgs e)
    {
        districts c = (districts)gridView1.GetRow(e.RowHandle);
        e.IsEmpty = c.districtparts.Count == 0;
    }

    private void gridView1_MasterRowGetRelationCount(object sender, DevExpress.XtraGrid.Views.Grid.MasterRowGetRelationCountEventArgs e)
    {
        e.RelationCount = 1;
    }

    private void gridView1_MasterRowGetRelationName(object sender, DevExpress.XtraGrid.Views.Grid.MasterRowGetRelationNameEventArgs e)
    {
        e.RelationName = "districtparts";
    }

    private void gridView1_MasterRowGetChildList(object sender, DevExpress.XtraGrid.Views.Grid.MasterRowGetChildListEventArgs e)
    {
        districts c = (districts)gridView1.GetRow(e.RowHandle);
        e.ChildList = new BindingSource(c, "districtparts");
    }
    #endregion

and that works fine: there is a grid, displaying my districts and I can expand each row and there displays another grid with districtparts The question is: what should I do to display votecallers. The goal is to have two levels of master-detail hierarchy. That means that districts should have districtparts, and districtparts should have votecallers.

Thanks.


Solution

  • Found a solution here

    And some irrelevant words to meet the requirement of 30 characters =)