Home Forums WPF controls Xceed DataGrid for WPF Master Detail Grid in Code

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • User (Old forums)
    Post count: 23064
    #27076 |

    How to implement Master Detail Grid in  Code . Please help me out  doing on code not in xaml , Binding the source to Grid , defining DetailsDescription ,DetailConfigurations ,DataRelationDetailDescription e.t.c


    Imported from legacy forums. Posted by Rachana (had 1622 views)

    Xceed Support
    Post count: 5658

    What code you have tried so far?

    Imported from legacy forums. Posted by Jenny [Xceed] (had 972 views)

    User (Old forums)
    Post count: 23064

    private void PopulateGrid()


    DataSet ds = new DataSet(“Master-Detail-SubDetail”);

    DataTable dt = new DataTable();


    new DataColumn(ENTITY_GRID_COLUMN_EID, typeof(int)));


    new DataColumn(ENTITY_GRID_COLUMN_ENAME, typeof(string)));


    new DataColumn(ENTITY_GRID_COLUMN_CITY, typeof(string)));


    new DataColumn(ENTITY_GRID_COLUMN_STATE, typeof(string)));


    new DataColumn(ENTITY_GRID_COLUMN_STATUS, typeof(string)));


    new DataColumn(ENTITY_GRID_COLUMN_CLASS, typeof(string)));


    new DataColumn(ENTITY_GRID_COLUMN_TYPE, typeof(string)));


    new DataColumn(ENTITY_GRID_COLUMN_NO_OF_BUILDINGS, typeof(int)));


    new DataColumn(ENTITY_GRID_COLUMN_NO_OF_UNITS, typeof(int)));


    new DataColumn(ENTITY_GRID_COLUMN_MEMO, typeof(string)));


    new DataColumn(ENTITY_GRID_COLUMN_SQUARE_FOOTAGE, typeof(string)));


    new DataColumn(ENTITY_GRID_COLUMN_ENTITY_DATE, typeof(DateTime)));


    new DataColumn(ENTITY_GRID_COLUMN_HIGHLIGHT, typeof(string)));

    EntityUI entityUI = new EntityUI();

    EntityDTO[] entities = entityUI.Lookup(new EntityDTO());

    BuildingUI buildingUI = new BuildingUI();

    BuildingDTO buildingDTO = new BuildingDTO();

    buildingDTO.entity =

    new EntityDTO();

    BuildingDTO[] buildings= buildingUI.Lookup(buildingDTO);


    DataRow dr = null;

    if (entities != null && entities.Length > 0)


    foreach (EntityDTO entity in entities)


    dr = dt.NewRow();

    dr[ENTITY_GRID_COLUMN_EID] = entity.entityId;

    dr[ENTITY_GRID_COLUMN_ENAME] = entity.entityName;

    dr[ENTITY_GRID_COLUMN_CITY] = entity.city;

    dr[ENTITY_GRID_COLUMN_STATE] = entity.state;

    dr[ENTITY_GRID_COLUMN_STATUS] = entity.status.statusName;

    dr[ENTITY_GRID_COLUMN_CLASS] = entity.keyFacts.classObj.className;

    dr[ENTITY_GRID_COLUMN_TYPE] = entity.keyFacts.type.typeName;

    dr[ENTITY_GRID_COLUMN_NO_OF_BUILDINGS] = entity.keyFacts.numberOfBuildings;

    dr[ENTITY_GRID_COLUMN_NO_OF_UNITS] = entity.keyFacts.numberOfUnits;

    dr[ENTITY_GRID_COLUMN_MEMO] = entity.keyFacts.memo;

    dr[ENTITY_GRID_COLUMN_SQUARE_FOOTAGE] = entity.keyFacts.squareFootage;

    dr[ENTITY_GRID_COLUMN_ENTITY_DATE] = entity.entGenInfo.entityDate;






    //return dt;


    DataTable dtDetail = new DataTable();


    new DataColumn(ENTITY_GRID_COLUMN_EID, typeof(int)));


    new DataColumn(ENTITY_GRID_COLUMN_ENAME, typeof(string)));


    new DataColumn(ENTITY_GRID_COLUMN_BID, typeof(int)));


    new DataColumn(ENTITY_GRID_COLUMN_BNAME, typeof(string)));


    new DataColumn(ENTITY_GRID_COLUMN_BSTATUS, typeof(string)));


    new DataColumn(ENTITY_GRID_COLUMN_BCLASS, typeof(string)));


    new DataColumn(ENTITY_GRID_COLUMN_BTYPE, typeof(string)));

    // dtDetail.Columns.Add(new DataColumn(ENTITY_GRID_COLUMN_NO_OF_BUNITS, typeof(int)));


    new DataColumn(ENTITY_GRID_COLUMN_BMEMO, typeof(string)));

    if (buildings != null && buildings.Length > 0)


    foreach (BuildingDTO building in buildings)


    dr = dtDetail.NewRow();

    dr[ENTITY_GRID_COLUMN_EID] = building.entity.entityId;

    dr[ENTITY_GRID_COLUMN_ENAME] = building.entity.entityName;

    dr[ENTITY_GRID_COLUMN_BID] = building.buildingId;

    dr[ENTITY_GRID_COLUMN_BNAME] = building.buildingName;

    dr[ENTITY_GRID_COLUMN_BSTATUS] = building.status.statusName;

    dr[ENTITY_GRID_COLUMN_BCLASS] = building.keyFacts.classObj.className;

    dr[ENTITY_GRID_COLUMN_BTYPE] = building.keyFacts.type.typeName;

    // dr[ENTITY_GRID_COLUMN_NO_OF_BUNITS] = building.keyFacts.numberOfUnits;

    dr[ENTITY_GRID_COLUMN_MEMO] = building.keyFacts.memo;







    // set up the relationship between Master -> Detail tables

    //Dim relMaster2Detail As New DataRelation(“Master->Detail”, _

    //ds.Tables(“Master”).Columns(“MasterID”), _


    //relMaster2Detail.Nested = True



    DataRelation drel = new DataRelation(“Master->Detail”, ds.Tables[“dt”].Columns[“ENTITY_GRID_COLUMN_EID”],



    drel.Nested =




    //grdDetail.SetDataBinding(ds.Tables(“Master”), “Master->Detail”)

    //grdDetail.HeaderRows.Add(New Xceed.Grid.ColumnManagerRow)

    //’ set up a detail grid for table: SubDetail

    //Dim grdSubDetail As New Xceed.Grid.DetailGrid

    //grdSubDetail.SetDataBinding(ds.Tables(“Detail”), “Detail->SubDetail”)

    //grdSubDetail.HeaderRows.Add(New Xceed.Grid.ColumnManagerRow)

    //’ add and update the detail grids




    Binding binding = new Binding();

    binding.Source =ds.Tables[



    DataGridControl.ItemsSourceProperty, binding);

    DataGridControl detgrd = new DataGridControl();

    Binding binding1 = new Binding();

    binding1.Source = ds.Tables[



    DataGridControl.ItemsSourceProperty, binding);



    Please tell me how to assign this Dataset to grid so that it can be displayed as master detail

     Or Entities is the Master  Table and Buildings is the details how to bind these 2 sources in to the Grid  , so that they can be displayed as master detail . Does this type of approach works only for .Net 2.0 not WPF. If so how can i do this in code in WPF

    DetailConfiguration dcf = new DetailConfiguration();

    dcf.AutoCreateColumns = true;

    dcf.AllowDetailToggle = true;


     Or can u tell me how to create  DetailConfiguration  , DataRelation e.tc.


    DataView dv = new DataView(dt);

    // Binding binding = new Binding();

    // binding.Source = dv;


    DataGridCollectionView dataGridCollectionView = new DataGridCollectionView((IEnumerable)dv);

    dataGridCollectionView.AutoFilterMode =


    dataGridCollectionView.DistinctValuesConstraint =





    SumFunction sf = new SumFunction();

    sf.SourcePropertyName = ENTITY_GRID_COLUMN_EID;

    sf.ResultPropertyName =





    StatRow sr = new StatRow();

    sr.Name =


    GroupConfiguration gc = new GroupConfiguration();

    DataTemplate dtemp = new DataTemplate();

    FrameworkElementFactory control = new FrameworkElementFactory(typeof(StatRow), sr.Name);

    StatCell sc = new StatCell();

    sc.FieldName = ENTITY_GRID_COLUMN_EID;

    sc.ResultPropertyName =




    dtemp.VisualTree = control;

    DataTemplate stTemp = this.FindResource(“statTemplate”) as DataTemplate;

    // gc.Footers.Add(dtemp);


    dataGrid.DefaultGroupConfiguration = gc;

    dataGrid.ItemsSource = dataGridCollectionView;

    // dataGrid.SetBinding(DataGridControl.ItemsSourceProperty, binding);


    Imported from legacy forums. Posted by Rachana (had 1303 views)

    User (Old forums)
    Post count: 23064

    Please help me out in coding the sample provided by  Xceed Samples

    Xceed.Wpf.DataGrid.Samples.MasterDetail.MainPage in  code behind 

    I want to bind both master grid and detail grid in code behind , how the detail grid can be assigned to master grid in code behind  in wpf .


    Imported from legacy forums. Posted by Rachana (had 1062 views)

    Xceed Support
    Post count: 5658

    Hi Rachana,

       I have problems understanding the structure of the code submitted as well as the nature of the problem. First, I will make abstraction of the section that setup the DataSet and DataTables, assuming it is valid.

       Also, I will make abstraction of the Xceed Grid for .NET code placed there. The Xceed DataGrid for WPF is not a port of the WinForms product and should be considered as independent regarding both API and feature set.

       Then, below the DataSet creation code, I see that you have actually 2 instances of DataGridControl (dataGrid and detgrd). Do you want to have 2 DataGridControls displayed side by side, the detail grid synchronized on the master? Or do you want to have the details expanded inside the master DataGridControl? For the later, you only need one instance of the DataGridControl.

       Furthermore, I can see that you are setting the ItemsSource property of the dataGrid instance multiple times. One time with the DefaultView from the DataTable and another time with a new DataView created from the same DataTable, wrapped by a DataGridCollectionView. I guess the code could be simplified a little bit by assigning the ItemsSource only once, with a DataGridCollectionView that wraps the dt.DefaultView.

      Then, as indicated by the product documentation, in the Master/Detail section, you need to either specify DetailDescriptions or to specify the flag AutoCreateDetailDescriptions on the DataGridCollectionView.

      If you do not want to go the “automatic” way, you can still specify DetailConfigurations manually, but please be advised that the DetailsConfigurations collection expects a DetailConfiguration object (not an IEnumerable).

      Finally, as a general note, although most people’s first impression of WPF are that XAML is useless and think they can build their application 100% in code-behind, XAML is actually a really important part of the framework and I truly believe that developpers should invest time to change their mindset towards the WPF architecture.

       Nervertheless, if you still want to program your complete application in code-behind, my advice is that you can convert any XAML code to C# by interpreting tags as property references and object declarations.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 2587 views)

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.