.Net 中使用Farpoint Web Spread 自定义CellType
网上关于Farpoint的文章不多,自己开发中有用到,写来总结一下。
FarPoint.Web.Spread可以在单元格中控制自己需要的CellType。 但有时候我们所面对的需求五花八门,可能它自带的CellType并不能满足我们的需要,这时,我们就可以选择自定义CellType。
一个自定义的HtmlInputButtonCellType的例子:
<Serializable()> Public Class PINButtonCellType
Inherits FarPoint.Web.Spread.BaseCellType
Public Value As String
Public OnClick As String
Public Overrides Function PaintCell(ByVal id As String, ByVal parent As TableCell, ByVal style As FarPoint.Web.Spread.Appearance, ByVal margin As FarPoint.Web.Spread.Inset, ByVal val As Object, ByVal ul As Boolean) As System.Web.UI.Control
'Manual realize JS function on client FpCellType value + _getValue(rd) _setEditorValue(ed, val) _getEditorValue(ed) _setValue(rd,val)
parent.Attributes.Add("FpCellType", "PINButtonCellType")
Dim lit As New System.Web.UI.HtmlControls.HtmlInputButton
lit.Value = Value
lit.Attributes.Add("onclick", String.Format(OnClick, val))
Return lit
End Function
Public Overrides Function GetEditorControl(ByVal id As String, ByVal tc As TableCell, ByVal style As FarPoint.Web.Spread.Appearance, ByVal margin As FarPoint.Web.Spread.Inset, ByVal v As Object, ByVal ul As Boolean) As System.Web.UI.Control
Return Nothing
End Function
Public Overrides Function GetEditorValue(ByVal owner As Control, ByVal id As String) As Object
Return MyBase.GetEditorValue(owner, id)
End Function
Public Overrides Function Format(ByVal o As Object) As String
Format = MyBase.Format(o)
End Function
Public Overrides Function Parse(ByVal s As String) As Object
Parse = MyBase.Parse(s)
End Function
Public Function GetValueFromText(ByVal s As String) As Object
GetValueFromText = s
End Function
End Class
使用示例:
Dim btnCellType As New PINButtonCellType btnCellType.Value = "Reset" 'button name btnCellType.OnClick = "ResetRadio(this)" 'onclick function fpsDemo.ActiveSheetView.Columns(0).CellType = btnCellType