Spread ASP.NET 17
FarPoint.Web.Spread Assembly / FarPoint.Web.Spread.Model Namespace / DefaultSheetDataModel Class / ParentRowIndex Property
Example


In This Topic
    ParentRowIndex Property (DefaultSheetDataModel)
    In This Topic
    Gets the index of the row in the parent data model associated with this child data model.
    Syntax
    'Declaration
     
    
    Public ReadOnly Property ParentRowIndex As Integer
    'Usage
     
    
    Dim instance As DefaultSheetDataModel
    Dim value As Integer
     
    value = instance.ParentRowIndex
    public int ParentRowIndex {get;}

    Property Value

    Integer row index of the parent
    Example
    This example creates a DefaultSheetDataModel and assigns it to the DataModel of the spreadsheet. The data source of the model is attached to some DataTables and the ParentRelationName and ParentRowIndex are returned to a list box.
    Private Sub Page_Load(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles MyBase.Load
    
    If(IsPostBack)Then Return
    
    Dim ds As New System.Data.DataSet()
    Dim dm As New FarPoint.Web.Spread.Model.DefaultSheetDataModel()
    FpSpread1.ActiveSheetView.DataModel=dm
    FpSpread1.HierarchicalView=True
    
    Dim emp As DataTable=New DataTable("Employee")
    Dim dept As DataTable=New DataTable("Department")
    
    Dim lname As DataColumn = New DataColumn("LastName",GetType(System.String))
    Dim fname As DataColumn = New DataColumn("FirstName",GetType(System.String))
    
    Dim dname As DataColumn = New DataColumn("DeptName",GetType(System.String))
    Dim area As DataColumn = New DataColumn("Area",GetType(System.String))
    
    Dim id As DataColumn = emp.Columns.Add("ID",GetType(System.Int32))
    id.AutoIncrement=True
    Dim primarykey As DataColumn() = New DataColumn(){id}
    emp.PrimaryKey=primarykey
    emp.Columns.Add(lname)
    emp.Columns.Add(fname)
    
    id=dept.Columns.Add("ID",GetType(System.Int32))
    id.AutoIncrement=True
    dept.PrimaryKey = New DataColumn(){id}
    id.AutoIncrement=True
    Dim lang As DataColumn = dept.Columns.Add("Language",GetType(System.Int32))
    Dim foreignkey As DataColumn() = New DataColumn(){lang}
    dept.Columns.Add(dname)
    dept.Columns.Add(area)
    
    ds.Tables.Add(emp)
    ds.Tables.Add(dept)
    
    Dim ti As DataRow=emp.NewRow()
    ti(lname)="Bazemoreland"
    ti(fname)="Ti"
    emp.Rows.Add(ti)
    
    Dim ginny As DataRow=emp.NewRow()
    ginny(lname)="Danielson"
    ginny(fname)="Ginny"
    emp.Rows.Add(ginny)
    
    Dim bob As DataRow=emp.NewRow()
    bob(lname)="Morrison"
    bob(fname)="Bob"
    emp.Rows.Add(bob)
    
    Dim rel As DataRelation= New DataRelation("FarPoint",primarykey,foreignkey,False)
    ds.Relations.Add(rel)
    
    Dim row As DataRow=dept.NewRow()
    row("Language")=ti("ID")
    row(dname)="TechSupport"
    row(area)="C#"
    dept.Rows.Add(row)
    
    row=dept.NewRow()
    row("Language")=ginny("ID")
    row(dname)="TechSupport"
    row(area)="VB.Net"
    dept.Rows.Add(row)
    row=dept.NewRow()
    row("Language")=bob("ID")
    row(dname)="TechSupport"
    row(area)="C#"
    dept.Rows.Add(row)
    ds.AcceptChanges()
    dm.DataSource=ds
    dm.DataMember="Employee"
    
    Dim dm2 As FarPoint.Web.Spread.Model.DefaultSheetDataModel
    dm2=FpSpread1.Sheets(0).GetChildView(0,0).DataModel
    ListBox1.Items.Add(dm2.ParentRelationName)
    ListBox1.Items.Add(dm2.ParentRowIndex)
    ListBox1.Items.Add(dm.ChildRelationCount)
    End Sub
    private void Page_Load(object sender,System.EventArgs e)
    {
    System.Data.DataSet ds = new System.Data.DataSet();
    FarPoint.Web.Spread.Model.DefaultSheetDataModel dm;
    dm = new FarPoint.Web.Spread.Model.DefaultSheetDataModel();
    FpSpread1.ActiveSheetView.DataModel = dm;
    FpSpread1.HierarchicalView=true;
    DataTable emp = new DataTable("Employee");
    DataTable dept = new DataTable("Department");
    
    DataColumn lname = new DataColumn("LastName",typeof(String));
    DataColumn fname = new DataColumn("FirstName",typeof(String));
    
    DataColumn dname = new DataColumn("DeptName",typeof(String));
    DataColumn area = new DataColumn("Area",typeof(String));
    
    DataColumn id = emp.Columns.Add("ID",typeof(Int32));
    id.AutoIncrement=true;
    emp.PrimaryKey=new DataColumn[]{id};
    emp.Columns.Add(lname);
    emp.Columns.Add(fname);
    
    id=dept.Columns.Add("ID",typeof(Int32));
    id.AutoIncrement=true;
    dept.PrimaryKey=new DataColumn[]{id};
    id.AutoIncrement=true;
    DataColumnlang=dept.Columns.Add("Language",typeof(Int32));
    DataColumn[]foreignkey=new DataColumn[]{lang};
    dept.Columns.Add(dname);
    dept.Columns.Add(area);
    
    ds.Tables.Add(emp);
    ds.Tables.Add(dept);
    
    DataRow ti=emp.NewRow();
    ti[lname]="Bazemoreland";
    ti[fname]="Ti";
    emp.Rows.Add(ti);
    
    DataRow ginny=emp.NewRow();
    ginny[lname]="Danielson";
    ginny[fname]="Ginny";
    emp.Rows.Add(ginny);
    
    DataRow bob=emp.NewRow();
    bob[lname]="Morrison";
    bob[fname]="Bob";
    emp.Rows.Add(bob);
    
    DataRelation rel = new DataRelation("FarPoint",emp.PrimaryKey,foreignkey,false);
    ds.Relations.Add(rel);
    
    DataRow row=dept.NewRow();
    row["Language"]=ti["ID"];
    row[dname]="TechSupport";
    row[area]="C#";
    dept.Rows.Add(row);
    
    row=dept.NewRow();
    row["Language"]=ginny["ID"];
    row[dname]="TechSupport";
    row[area]="VB.Net";
    dept.Rows.Add(row);
    row=dept.NewRow();
    row["Language"]=bob["ID"];
    row[dname]="TechSupport";
    row[area]="C#";
    dept.Rows.Add(row);
    ds.AcceptChanges();
    dm.DataSource=ds;
    dm.DataMember="Employee";
    FarPoint.Web.Spread.Model.DefaultSheetDataModel dm2;
    dm2=(FarPoint.Web.Spread.Model.DefaultSheetDataModel)FpSpread1.Sheets[0].GetChildView(0,0).DataModel;
    ListBox1.Items.Add(dm2.ParentRelationName);
    ListBox1.Items.Add(Convert.ToString(dm2.ParentRowIndex));
    ListBox1.Items.Add(Convert.ToString(dm.ChildRelationCount));
    }
    See Also