找回密码
 立即注册

QQ登录

只需一步,快速开始

jplzj
论坛元老   /  发表于:2013-11-27 15:04:00
21#
能否帮忙实现重载 Serialize 和 Deserialize 方法?
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2013-11-27 16:18:00
22#
回复 21楼jplzj的帖子

jplzj 你好,

自定义单元格类型实现 Serialize 和 Deserialize 方法属于自定义范畴,不是我们产品的内置功能。我们一般建议用户自主实现。

我这边可以尝试,大体的思路为实现 ISerializeSupport  接口。

有新的信息会共享给你。如果你那边有进展也请共享给我。
回复 使用道具 举报
jplzj
论坛元老   /  发表于:2013-11-27 20:05:00
23#
期待中,让我们一起努力!
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2013-11-28 09:03:00
24#
回复 使用道具 举报
jplzj
论坛元老   /  发表于:2013-11-29 19:51:00
25#
以解决,发出共享。
Imports System
Imports System.ComponentModel
Imports System.Runtime.Serialization
Imports System.Security.Permissions
Imports System.Text.RegularExpressions
Imports System.Windows.Forms
Imports System.Xml
Imports System.Xml.Serialization
Imports System.Drawing
Imports FarPoint.Win
Imports FarPoint.Win.SuperEdit
Imports System.Globalization
Imports System.Collections
Imports System.Collections.Specialized
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Imports System.Windows.Forms.VisualStyles

<Serializable()> _
Public Class MyComboCellType
    Inherits FarPoint.Win.Spread.CellType.GeneralCellType
    Implements ISerializeSupport
    Dim editor As FarPoint.Win.FpCombo
    Dim ItemSource As Dictionary(Of String, String)
    Public Sub New()
    End Sub
  
    Public Sub New(ByVal data As Dictionary(Of String, String))
        ItemSource = Data
        Dim l_Items As New List(Of String)
        Dim l_Itemdata As New List(Of String)
        For Each key As String In Data.Keys
            l_Items.Add(Data(key))
            l_Itemdata.Add(key)
        Next
        editor = New FarPoint.Win.FpCombo()
        editor.Editable = True
        editor.BorderStyle = BorderStyle.None
        editor.BackgroundColor = Color.White
        editor.List.AddRange(l_Items.ToArray())
        editor.ItemData.AddRange(l_Itemdata.ToArray())

    End Sub

    Public Overrides Sub PaintCell(ByVal g As System.Drawing.Graphics, ByVal r As System.Drawing.Rectangle, ByVal appearance As FarPoint.Win.Spread.Appearance, ByVal value As Object, ByVal isSelected As Boolean, ByVal isLocked As Boolean, ByVal zoomFactor As Single)
        If Not value Is Nothing Then
            Try
                value = ItemSource(value.ToString())
            Catch ex As Exception
            End Try

        End If
        MyBase.PaintCell(g, r, appearance, value, isSelected, isLocked, zoomFactor)
    End Sub

    Public Overrides Function GetEditorControl(ByVal parent As System.Windows.Forms.Control, ByVal appearance As FarPoint.Win.Spread.Appearance, ByVal zoomFactor As Single) As System.Windows.Forms.Control
        Return editor
    End Function

    Public Overrides Function GetEditorValue() As Object

        If editor.SelectedIndex = -1 Then
            Return Nothing
        End If

        For Each key As String In ItemSource.Keys
            If ItemSource(key).Equals(editor.SelectedItem.ToString()) Then
                Return key
            End If
        Next

        Return Nothing
    End Function

    Public Overrides Sub SetEditorValue(ByVal value As Object)

        Dim index As Integer = -1

        If value Is Nothing Then
            editor.Text = ""
            editor.SelectedIndex = index
            Return
        End If

        For Each key As String In ItemSource.Keys
            index = index + 1
            If key.Equals(value.ToString()) Then
                editor.SelectedIndex = index
                Return
            End If
        Next

    End Sub
    Dim ItemsourceString As String = ""
    Public Overrides Function Serialize(ByVal w As XmlTextWriter) As Boolean
        w.WriteElementString("ItemSource", ItemsourceString)
        w.WriteElementString("_Dictionaryname", _Dictionaryname)
        MyBase.Serialize(w)
    End Function
    Public Overrides Function Deserialize(ByVal r As XmlNodeReader) As Boolean
        '  MessageBox.Show("Deserialize" &amp; ItemsourceString)
        MyBase.Deserialize(r)
    End Function

    Public Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
        MyBase.New(info, context)
        Me.ItemsourceString = info.GetString("ItemSource")
        Dim data As New Dictionary(Of String, String)
        data.Add(ItemsourceString.Split(":")(1), ItemsourceString.Split(":")(0))
        ItemSource = data
        Dim l_Items As New List(Of String)
        Dim l_Itemdata As New List(Of String)
        For Each key As String In data.Keys
            l_Items.Add(data(key))
            l_Itemdata.Add(key)
        Next
        editor = New FarPoint.Win.FpCombo()
        editor.Editable = True
        editor.BorderStyle = BorderStyle.None
        editor.BackgroundColor = Color.White
        editor.List.AddRange(l_Items.ToArray())
        editor.ItemData.AddRange(l_Itemdata.ToArray())
    End Sub
    Public Overrides Sub GetObjectData(ByVal info As SerializationInfo, ByVal context As StreamingContext)
        For Each key As String In ItemSource.Keys
            ItemsourceString = ItemSource(key) &amp; ":" &amp; key
        Next
        info.AddValue("ItemSource", ItemsourceString)
        MyBase.GetObjectData(info, context)
    End Sub
End Class
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2013-12-2 09:10:00
26#
回复 25楼jplzj的帖子

回复 使用道具 举报
123
您需要登录后才可以回帖 登录 | 立即注册
返回顶部