Spread ASP.NET 17
FarPoint.Web.Spread Assembly / FarPoint.Web.Spread.Model Namespace / DefaultSheetDataModel Class / SetModelDataColumn Method / SetModelDataColumn(Int32,Int32) Method
Column index in the model
Data source column
Example


In This Topic
    SetModelDataColumn(Int32,Int32) Method
    In This Topic
    Binds the model column to a specified data source column.
    Syntax
    'Declaration
     
    
    Public Overloads Sub SetModelDataColumn( _
       ByVal column As Integer, _
       ByVal value As Integer _
    ) 
    'Usage
     
    
    Dim instance As DefaultSheetDataModel
    Dim column As Integer
    Dim value As Integer
     
    instance.SetModelDataColumn(column, value)
    public void SetModelDataColumn( 
       int column,
       int value
    )

    Parameters

    column
    Column index in the model
    value
    Data source column
    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 SetModelDataColumn method rearranges which columns of the model are bound to which columns in the DataSet.
    Private Sub Page_Load(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles MyBase.Load
    
    If(IsPostBack)Then Return
    
    Dim dsAs New System.Data.DataSet()
    Dim dm As New FarPoint.Web.Spread.Model.DefaultSheetDataModel()
    FpSpread1.ActiveSheetView.DataModel=dm
    
    Dim emp As DataTable=New DataTable("Employee")
    
    Dim lname As DataColumn=New DataColumn("LastName",GetType(System.String))
    Dim fname As DataColumn=New DataColumn("FirstName",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)
    
    ds.Tables.Add(emp)
    
    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)
    
    ds.AcceptChanges()
    dm.DataSource=ds
    dm.SetModelDataColumn(0,"FirstName")
    dm.SetModelDataColumn(2,0)
    End Sub
    private void Page_Load(object sender,System.EventArgs e)
    {
    if(this.IsPostBack)return;
    
    System.Data.DataSet ds=new System.Data.DataSet();
    FarPoint.Web.Spread.Model.DefaultSheetDataModel dm=new FarPoint.Web.Spread.Model.DefaultSheetDataModel();
    FpSpread1.ActiveSheetView.DataModel=dm;
    DataTable emp=new DataTable("Employee");
    DataColumn lname=new DataColumn("LastName",typeof(String));
    DataColumn fname=new DataColumn("FirstName",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);
    
    ds.Tables.Add(emp);
    
    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);
    
    ds.AcceptChanges();
    dm.DataSource=ds;
    dm.SetModelDataColumn(0,"FirstName");
    dm.SetModelDataColumn(2,0);
    }
    See Also