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())
End Sub
<Serializable()> _
Public Class OrderItem
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
End Sub
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()> _
Public Class OrderList
Inherits FarPoint.Web.Spread.Model.BaseSheetDataModel
Implements FarPoint.Web.Spread.Model.IDataSourceSupport
Private orders As ArrayList = New ArrayList()
Public ReadOnly Property UseRowIndex() As Boolean
Get
Return False
End Get
End Property
Public Function GetKey(ByVal index As Integer) As Object
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) As OrderItem
Get
Dim elems As IEnumerator = orders.GetEnumerator()
While (elems.MoveNext())
Dim e As OrderItem = elems.Current
If (e.Name = name) Then
Return e
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
Get
Return 0
End Get
Set(ByVal Value As Integer)
End Set
End Property
Public Property ParentRelationName() As String
Get
Return Nothing
End Get
Set(ByVal Value As String)
End Set
End Property
Public ReadOnly Property ChildRelationCount() As Integer
Get
Return 0
End Get
End Property
Public Property Parent() As FarPoint.Web.Spread.Model.IDataSourceSupport
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
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 void Page_Load(object sender, System.EventArgs e)
{
if (this.IsPostBack) return;
OrderList data = 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());
}
[Serializable()]
public class OrderItem
{
public int productID;
public int quantity;
public String name;
public double price;
public OrderItem(int productID, String name, 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)
{
case 0:
//Qty
OrderItem oi = (OrderItem)orders[c];
return oi.Quantity;
case 1:
//Name
oi = (OrderItem)orders[c];
return oi.Name;
case 2:
//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.IDataSourceSupport Parent
{
get
{
return null;
}
set { }
}
public string GetChildRelation(int index) { return null; }
public DataView GetDataView(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.ISheetDataModel GetChildDataModel(int row, string relation) { return null; }
}