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


In This Topic
    UseRowIndex Property (DefaultSheetDataModel)
    In This Topic
    Gets whether the GetKey method generates a key for a row.
    Syntax
    'Declaration
     
    
    Public ReadOnly Property UseRowIndex As Boolean
    'Usage
     
    
    Dim instance As DefaultSheetDataModel
    Dim value As Boolean
     
    value = instance.UseRowIndex
    public bool UseRowIndex {get;}

    Property Value

    Boolean: true if the GetKey method takes the row index as the parameter; false if the GetKey method takes the column index as parameter
    Remarks
    This property is true if the GetKey method generates a key for the specified row and false if the GetKey method generates a key for the specified column.
    Example
    This example displays a list of products in the spread. The GetKey method returns the name of the product.
    <Serializable()>_
    PublicClassOrderItem
    Dim id As Integer
    Dim qty As Integer
    Dim oname As String
    Dim oprice As Double
    
    Public Sub New(ByVal productID As Integer,ByVal name As String,ByVal price As Double,ByVal quantity As Integer)
    Me.id=productID
    Me.qty=quantity
    Me.oname=name
    Me.oprice=price
    EndSub
    
    Public ReadOnly Property ProductID() As Integer
    Get
    Return id
    End Get
    End Property
    
    Public Property Quantity() As Integer
    Get
    Return qty
    End Get
    Set(ByVal Value As Integer)
    qty=Value
    End Set
    End Property
    
    Public ReadOnly Property Name() As String
    Get
    Return oname
    End Get
    End Property
    
    Public ReadOnly Property Price() As Double
    Get
    Return oprice
    End Get
    End Property
    End Class
    
    <Serializable()>_
    PublicClassOrderList
    Inherits FarPoint.Web.Spread.Model.BaseSheetDataModel
    Implements FarPoint.Web.Spread.Model.IDataSourceSupport
    
    Private orders As ArrayList = New ArrayList()
    
    Public ReadOnly Property UseRowIndex() As Boolean Implements FarPoint.Web.Spread.Model.IDataSourceSupport.UseRowIndex
    Get
    Return False
    End Get
    End Property
    
    Public Function GetKey(ByVal index As Integer) As Object Implements FarPoint.Web.Spread.Model.IDataSourceSupport.GetKey
    Dim oi As OrderItem=orders(index)
    Return oi.Name
    End Function
    
    Public Overrides Property RowCount() As Integer
    Get
    Return 3
    End Get
    Set(ByVal Value As Integer)
    
    End Set
    End Property
    
    Public Overrides Property ColumnCount() As Integer
    Get
    Return orders.Count
    End Get
    Set(ByVal Value As Integer)
    
    End Set
    End Property
    
    Public Overrides Function GetValue(ByVal r As Integer,ByVal c As Integer)As Object
    If(r=0)Then
    Dim oi As OrderItem=orders(c)
    Return oi.Quantity
    ElseIf(r=1)Then
    Dim oi As OrderItem=orders(c)
    Return oi.name
    ElseIf(r=2)Then
    Dim oi As OrderItem=orders(c)
    Return oi.price
    End If
    Return""
    End Function
    
    Public Function GetColumnName(ByVal col As Integer)As String
    Return Nothing
    End Function
    
    Public ReadOnly Property Item(ByVal name As String)
    Get
    
    Dim elems As IEnumerator=orders.GetEnumerator()
    While(elems.MoveNext())
    Dim e As OrderItem=elems.Current
    If(e.Name=name)Then
    Return Item
    End If
    End While
    Return Nothing
    End Get
    End Property
    
    Public Sub Add(ByVal value As OrderItem)
    If(Me.Item(value.Name)=Nothing)Then
    orders.Add(value)
    Else
    Dim oI As OrderItem=Me.Item(value.Name)
    oI.Quantity=oI.Quantity+1
    End If
    End Sub
    
    Public Sub ClearCart()
    orders.Clear()
    End Sub
    
    Public Property DataSource() As Object Implements FarPoint.Web.Spread.Model.IDataSourceSupport.DataSource
    Get
    Return Nothing
    End Get
    Set(ByVal Value As Object)
    End Set
    End Property
    
    Public Property DataMember() As String Implements FarPoint.Web.Spread.Model.IDataSourceSupport.DataMember
    Get
    Return Nothing
    End Get
    Set(ByVal Value As String)
    
    End Set
    End Property
    
    Public Property DataKeyField() As Object Implements FarPoint.Web.Spread.Model.IDataSourceSupport.DataKeyField
    Get
    Return Nothing
    End Get
    Set(ByVal Value As Object)
    
    End Set
    End Property
    
    Public Function GetDataColumnName(ByVal column As Integer)As String Implements FarPoint.Web.Spread.Model.IDataSourceSupport.GetDataColumnName
    Return String.Empty
    End Function
    Public Property ParentRowIndex() As Integer Implements FarPoint.Web.Spread.Model.IDataSourceSupport.ParentRowIndex
    Get
    Return 0
    End Get
    Set(ByVal Value As Integer)
    
    End Set
    End Property
    
    Public Property ParentRelationName() As String Implements FarPoint.Web.Spread.Model.IDataSourceSupport.ParentRelationName
    Get
    Return Nothing
    End Get
    Set(ByVal Value As String)
    
    End Set
    End Property
    
    Public ReadOnly Property ChildRelationCount() As Integer Implements FarPoint.Web.Spread.Model.IDataSourceSupport.ChildRelationCount
    Get
    Return 0
    End Get
    End Property
    
    Public Property Parent() As FarPoint.Web.Spread.Model.IDataSourceSupport Implements FarPoint.Web.Spread.Model.IDataSourceSupport.Parent
    Get
    Return Nothing
    End Get
    Set(ByVal Value As FarPoint.Web.Spread.Model.IDataSourceSupport)
    
    End Set
    End Property
    
    Public Function GetChildRelation(ByVal index As Integer)As String Implements FarPoint.Web.Spread.Model.IDataSourceSupport.GetChildRelation
    Return Nothing
    End Function
    
    Public Function GetDataView(ByVal create As Boolean)As DataView Implements FarPoint.Web.Spread.Model.IDataSourceSupport.GetDataView
    Return Nothing
    End Function
    
    Public Sub SetModelDataColumn(ByVal column As Integer,ByVal name As String)Implements FarPoint.Web.Spread.Model.IDataSourceSupport.SetModelDataColumn
    End Sub
    
    Public Function GetDataRowFromModelRow(ByVal row As Integer)As Integer Implements FarPoint.Web.Spread.Model.IDataSourceSupport.GetDataRowFromModelRow
    Return 0
    End Function
    
    Public Function GetModelRowFromDataRow(ByVal row As Integer)As Integer Implements FarPoint.Web.Spread.Model.IDataSourceSupport.GetModelRowFromDataRow
    Return 0
    End Function
    
    Public Function GetDataColumnFromModelColumn(ByVal column As Integer)As Integer Implements FarPoint.Web.Spread.Model.IDataSourceSupport.GetDataColumnFromModelColumn
    Return 0
    End Function
    
    Public Function GetModelColumnFromDataColumn(ByVal column As Integer)As Integer Implements FarPoint.Web.Spread.Model.IDataSourceSupport.GetModelColumnFromDataColumn
    Return 0
    End Function
    
    Public Function IsColumnBound(ByVal column As Integer)As Boolean Implements FarPoint.Web.Spread.Model.IDataSourceSupport.IsColumnBound
    Return False
    End Function
    
    Public Property AutoGenerateColumns()As Boolean Implements FarPoint.Web.Spread.Model.IDataSourceSupport.AutoGenerateColumns
    Get
    Return False
    End Get
    Set(ByVal Value As Boolean)
    
    End Set
    End Property
    
    Public Function IsColumnBound(ByVal row As Integer,ByVal relation As String)As Boolean
    Return Nothing
    End Function
    
    Public Function GetChildDataModel(ByVal row As Integer,ByVal relation As String)As FarPoint.Web.Spread.Model.ISheetDataModel Implements FarPoint.Web.Spread.Model.IDataSourceSupport.GetChildDataModel
    Return Nothing
    End Function
    
    End Class
    
    Private Sub Page_Load(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles MyBase.Load
    
    If(Me.IsPostBack)Then Return
    
    Dim Data As OrderList = New OrderList()
    Data.Add(New OrderItem(1,"P1",10.0,10))
    Data.Add(New OrderItem(2,"P2",20.0,5))
    Data.Add(New OrderItem(3,"P3",30.0,1))
    
    FpSpread1.ActiveSheetView.DataModel=Data
    ListBox1.Items.Add(Data.GetKey(1).ToString())
    
    EndSub
    [Serializable()]
    public class OrderItem
    {
    public int productID;
    public int quantity;
    public String name;
    public double price;
    
    public OrderItem(int productID,String names,double price,int quantity)
    {
    this.productID=productID;
    this.quantity=quantity;
    this.name=name;
    this.price=price;
    }
    
    public int ProductID
    {
    get{return productID;}
    }
    
    public int Quantity
    {
    get{return quantity;}
    set{quantity=value;}
    }
    
    public String Name
    {
    get{return name;}
    }
    
    public double Price
    {
    get{return price;}
    }
    }
    
    [Serializable()]
    public class OrderList:FarPoint.Web.Spread.Model.BaseSheetDataModel,FarPoint.Web.Spread.Model.IDataSourceSupport
    {
    private ArrayList orders=new ArrayList();
    
    public bool UseRowIndex
    {
    get{return false;}
    }
    
    public object GetKey(int index)
    {
    OrderItem oi=(OrderItem)orders[index];
    return oi.Name;
    }
    
    public override int RowCount
    {
    get{return 3;}
    }
    
    public override int ColumnCount
    {
    get{return orders.Count;}
    }
    
    public override object GetValue(int r,int c)
    {
    switch(r)
    {
    case0:
    //Qty
    OrderItem oi=(OrderItem)orders[c];
    return oi.Quantity;
    case1:
    //Name
    oi=(OrderItem)orders[c];
    return oi.Name;
    case2:
    //Price
    oi=(OrderItem)orders[c];
    return oi.Price;
    }
    
    return"";
    }
    
    public string GetColumnName(int col)
    {
    return null;
    }
    
    public OrderItem this[String name]
    {
    get
    {
    IEnumerator items=orders.GetEnumerator();
    while(items.MoveNext())
    {
    OrderItem item=(OrderItem)items.Current;
    if(item.Name==name)return item;
    }
    
    return null;
    }
    }
    
    public void Add(OrderItem value)
    {
    if(this[value.Name]==null)
    {
    orders.Add(value);
    }
    else
    {
    OrderItem oI=(OrderItem)this[value.Name];
    oI.Quantity=oI.Quantity+1;
    }
    }
    
    public void ClearCart()
    {
    orders.Clear();
    }
    
    public object DataSource
    {
    get
    {
    return null;
    }
    set{}
    }
    public string DataMember
    {
    get
    {
    return null;
    }
    set{}
    }
    public object DataKeyField
    {
    get
    {
    return null;
    }
    set{}
    }
    public string GetDataColumnName(int column){return null;}
    public int ParentRowIndex
    {
    get
    {
    return 0;
    }
    set{}
    }
    public string ParentRelationName
    {
    get
    {
    return null;
    }
    set{}
    }
    public int ChildRelationCount{get{return 0;}}
    public FarPoint.Web.Spread.Model.IDataSourceSupportParent
    {
    get
    {
    return null;
    }
    set{}
    }
    public stringGetChildRelation(int index){return null;}
    public DataViewGetDataView(bool create){return null;}
    public void SetModelDataColumn(int column,string columnName){}
    public int GetDataRowFromModelRow(int row){return-1;}
    public int GetModelRowFromDataRow(int row){return-1;}
    public int GetDataColumnFromModelColumn(int column){return-1;}
    public int GetModelColumnFromDataColumn(int column){return-1;}
    public bool IsColumnBound(int column){return false;}
    public bool AutoGenerateColumns{get{return false;}set{}}
    public FarPoint.Web.Spread.Model.ISheetDataModelGetChildDataModel(int row,string relation){return null;}
    }
    
    private void Page_Load(object sender, System.EventArgs e)
    {
    if(this.IsPostBack)return;
    
    OrderListdata=new OrderList();
    data.Add(new OrderItem(1,"P1",10.0,10));
    data.Add(new OrderItem(2,"P2",20.0,5));
    data.Add(new OrderItem(3,"P3",30.0,1));
    
    FpSpread1.ActiveSheetView.DataModel=data;
    ListBox1.Items.Add(data.GetKey(1).ToString());
    }
    See Also