Nevron Open Vision Documentation
Grid / Data Processing / Self Referencing
In This Topic
    Self Referencing
    In This Topic
     About Self-Referencing

    Self-referencing is only applicable to the Tree Grid. Self-referencing produces a tree-like structure from a tabular data source. This is achieved by specifying two fields of the data source - one that identifies each record uniquely and another that specifies the parent record of the record. The following images demonstrates a tabular data source that can be presented as a tree structure: 

    figure 1. Tabular Data Source figure 2. Tree Grid

    The image on the left illustrates a tabular data source, which has a tree structure encoded in it. This is achieved by two fields - the Id field uniquely identifies each record from the data source, while the Parent Id field specifies the id of the record that is considered as record parent. The hierarchy encoded on the left is represented by a tree grid on the right. The following code example demonstrates how to create a tree grid from code:

    My First Tree Grid
    Copy Code
    // create a hieararchical data table that represents a simple organization.
    NMemoryDataTable dataTable = new NMemoryDataTable(new NFieldInfo[]{
        new NFieldInfo("Id", typeof(Int32)),
        new NFieldInfo("Parent Id", typeof(Int32)),
        new NFieldInfo("Name", typeof(String)),
        new NFieldInfo("Job Title", typeof(ENJobTitle)),
    });
                   
    dataTable.AddRow(0, -1, "Jinny Collazo", ENJobTitle.President);
    dataTable.AddRow(1, 0,  "John Duke", ENJobTitle.VicePresident);
    dataTable.AddRow(2, 1,  "Kellie Ferrell", ENJobTitle.SalesManager);
    dataTable.AddRow(3, 2,  "Sibyl Woosley",  ENJobTitle.SalesRepresentative);
    dataTable.AddRow(4, 2,  "Kourtney Mattoon",ENJobTitle.SalesRepresentative);
    dataTable.AddRow(5, 1,  "Bruce Fail", ENJobTitle.LeadDevelop);
    dataTable.AddRow(6, 5,  "Dario Karl", ENJobTitle.SeniorDeveloper);
    dataTable.AddRow(7, 5, "Aliza Sermons", ENJobTitle.SeniorDeveloper);
                   
    // create a tree grid view and get its grid
    NTreeGridView treeGridView = new NTreeGridView();
    NTreeGrid treeGrid = treeGridView.Grid;
    // bind the grid to data
    treeGrid.IdFieldName = "Id";
    treeGrid.ParentIdFieldName = "Parent Id";
    treeGrid.CreateColumnsForServiceFieldNames = false;
    treeGrid.DataSource = new NDataSource(dataTable);
    
     Tree Grid Data Binding

    Besides the DataSource property that you need to specify, the tree grid also features three other properties that control its data binding as demonstrated by the My First Tree Grid example. They are:

    Property Description
    IdFieldName Specifies the field from the data source, which identifies the records uniquely.
    ParentIdFieldName Specifies the field of the data source, which defines the id of the parent record.
    CreateColumnsForServiceFieldNames Specifies whether columns should be automatically generated for the fields specified by the IdFieldName and ParentFieldName properties (service field names). By default the value of this property is true, meaning that the fields specified by the IdFieldName and ParentFieldName properties are not represented by automatically generated columns.