Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1369
Manually adding ExpansionRecord and ChildRecords?
posted

Hi,

 If I don't bind the grid with a datasource, how can I create either in xaml or in code behind, the expandable record and it's childs?  Thanks,

  • 8576
    Offline posted
    Hi -
     
    The xamDataGrid detects the presence of child records by looking at the data type of the Fields in a (parent) record.  When it encounters a Field that is of type IEnumerable, it treats the entries returned by IEnumerable as child records of the parent record.  It then automatically places a +/- expansion indicator in front of the parent record and displays the child records in a nested/indented 'island'.
     
    So one way to create a series of records with a parent/child relationship in code behind would be to:
    • define 2 CLR objects
    • ensure that the CLR object representing the parent records has a property that returns a value which supports IEnumerable (e.g., ObservableCollection).  This is the property that the xamDataGrid will automatically detect and which will expose the list of child records for a given parent record instance.  Note that the parent object can have other non-IEnumerable properties defined as well - these will be shown as 'columns' in the grid
    • the CLR object that represents the child records can expose whatever properties you need - these will be displayed as 'columns' in the nested child 'island'
    • To get instances of these objects into the grid, you have 2 choices:
      • add instances of the parent CLR object to a collection in code behind and set the collection to the xamDataGrid's DataSource property
      • add instances of the parent CLR object to xamDataGrid.DataItems using xamDataGrid.DataItems.Add(parentObjectInstance)
    When you add the instances of the parent objects in one of the above two ways, be sure to add instances of the child objects to the IEnumerable list property on the parent object instance.
     
    Joe